@kirkelliott/zap 0.1.3 → 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 +16 -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 : ''}`);
@@ -110,7 +123,9 @@ async function init(region) {
110
123
  try {
111
124
  const { Configuration } = await lambda.send(new client_lambda_1.GetFunctionCommand({ FunctionName: FUNCTION }));
112
125
  functionArn = Configuration.FunctionArn;
126
+ await (0, client_lambda_1.waitUntilFunctionUpdated)({ client: lambda, maxWaitTime: 60 }, { FunctionName: FUNCTION });
113
127
  await lambda.send(new client_lambda_1.UpdateFunctionCodeCommand({ FunctionName: FUNCTION, ZipFile: zip }));
128
+ await (0, client_lambda_1.waitUntilFunctionUpdated)({ client: lambda, maxWaitTime: 60 }, { FunctionName: FUNCTION });
114
129
  await lambda.send(new client_lambda_1.UpdateFunctionConfigurationCommand({ FunctionName: FUNCTION, Environment: { Variables: env } }));
115
130
  }
116
131
  catch (err) {
@@ -135,10 +150,6 @@ async function init(region) {
135
150
  try {
136
151
  const { FunctionUrl } = await lambda.send(new client_lambda_1.GetFunctionUrlConfigCommand({ FunctionName: FUNCTION }));
137
152
  await lambda.send(new client_lambda_1.UpdateFunctionUrlConfigCommand({ FunctionName: FUNCTION, AuthType: 'NONE', Cors: { AllowOrigins: ['*'], AllowMethods: ['*'], AllowHeaders: ['*'] } }));
138
- try {
139
- await lambda.send(new client_lambda_1.AddPermissionCommand({ FunctionName: FUNCTION, StatementId: 'public-access', Action: 'lambda:InvokeFunctionUrl', Principal: '*', FunctionUrlAuthType: 'NONE' }));
140
- }
141
- catch { }
142
153
  url = FunctionUrl;
143
154
  }
144
155
  catch (err) {
@@ -149,15 +160,9 @@ async function init(region) {
149
160
  AuthType: 'NONE',
150
161
  Cors: { AllowOrigins: ['*'], AllowMethods: ['*'], AllowHeaders: ['*'] },
151
162
  }));
152
- await lambda.send(new client_lambda_1.AddPermissionCommand({
153
- FunctionName: FUNCTION,
154
- StatementId: 'public-access',
155
- Action: 'lambda:InvokeFunctionUrl',
156
- Principal: '*',
157
- FunctionUrlAuthType: 'NONE',
158
- }));
159
163
  url = FunctionUrl;
160
164
  }
165
+ await allowPublicUrl(lambda, functionArn);
161
166
  done();
162
167
  (0, node_fs_1.writeFileSync)('.zaprc', JSON.stringify({ bucket, function: FUNCTION, table: TABLE, region, url, functionArn }, null, 2));
163
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.3",
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": {