@kirkelliott/zap 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/init.js +14 -11
  2. package/package.json +1 -1
package/dist/init.js CHANGED
@@ -24,6 +24,19 @@ const policy = (bucket) => JSON.stringify({
24
24
  { Effect: 'Allow', Action: ['dynamodb:GetItem', 'dynamodb:PutItem', 'dynamodb:DeleteItem'], Resource: `arn:aws:dynamodb:*:*:table/${TABLE}` },
25
25
  ],
26
26
  });
27
+ async function allowPublicUrl(lambda, functionArn) {
28
+ try {
29
+ await lambda.send(new client_lambda_1.RemovePermissionCommand({ FunctionName: functionArn, StatementId: 'public-access' }));
30
+ }
31
+ catch { }
32
+ await lambda.send(new client_lambda_1.AddPermissionCommand({
33
+ FunctionName: functionArn,
34
+ StatementId: 'public-access',
35
+ Action: 'lambda:InvokeFunctionUrl',
36
+ Principal: '*',
37
+ FunctionUrlAuthType: 'NONE',
38
+ }));
39
+ }
27
40
  function step(label) {
28
41
  process.stdout.write(` ${label.padEnd(24)}`);
29
42
  return (note = '') => console.log(`✓${note ? ' ' + note : ''}`);
@@ -137,10 +150,6 @@ async function init(region) {
137
150
  try {
138
151
  const { FunctionUrl } = await lambda.send(new client_lambda_1.GetFunctionUrlConfigCommand({ FunctionName: FUNCTION }));
139
152
  await lambda.send(new client_lambda_1.UpdateFunctionUrlConfigCommand({ FunctionName: FUNCTION, AuthType: 'NONE', Cors: { AllowOrigins: ['*'], AllowMethods: ['*'], AllowHeaders: ['*'] } }));
140
- try {
141
- await lambda.send(new client_lambda_1.AddPermissionCommand({ FunctionName: FUNCTION, StatementId: 'public-access', Action: 'lambda:InvokeFunctionUrl', Principal: '*', FunctionUrlAuthType: 'NONE' }));
142
- }
143
- catch { }
144
153
  url = FunctionUrl;
145
154
  }
146
155
  catch (err) {
@@ -151,15 +160,9 @@ async function init(region) {
151
160
  AuthType: 'NONE',
152
161
  Cors: { AllowOrigins: ['*'], AllowMethods: ['*'], AllowHeaders: ['*'] },
153
162
  }));
154
- await lambda.send(new client_lambda_1.AddPermissionCommand({
155
- FunctionName: FUNCTION,
156
- StatementId: 'public-access',
157
- Action: 'lambda:InvokeFunctionUrl',
158
- Principal: '*',
159
- FunctionUrlAuthType: 'NONE',
160
- }));
161
163
  url = FunctionUrl;
162
164
  }
165
+ await allowPublicUrl(lambda, functionArn);
163
166
  done();
164
167
  (0, node_fs_1.writeFileSync)('.zaprc', JSON.stringify({ bucket, function: FUNCTION, table: TABLE, region, url, functionArn }, null, 2));
165
168
  console.log(`\n → ${url.trim()}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirkelliott/zap",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Drop a .zap file in S3. It becomes an API endpoint.",
5
5
  "main": "dist/handler.js",
6
6
  "bin": {