Skip to content

Commit 21a4e01

Browse files
committed
Initial commit
0 parents  commit 21a4e01

File tree

6 files changed

+5654
-0
lines changed

6 files changed

+5654
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Front End Specific
2+
node_modules
3+
npm-debug.log
4+
.DS_Store
5+
dist
6+
/build
7+
tmp
8+
.tmp
9+
yarn.lock
10+
11+
## Directory-based project format:
12+
.idea/
13+
14+
## File-based project format:
15+
*.ipr
16+
*.iws
17+
*.iml
18+
19+
.DS_Store
20+
21+
# File used to map webpack alias to resources in Webstorm
22+
ws-webpack-alias.js

README.md

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# update-lambda-edge
2+
3+
Provides some handy functions for pushing new code to Lambda@Edge and updating CloudFront triggers.
4+
5+
## Install
6+
7+
```sh
8+
$ npm i update-lambda-edge -g
9+
```
10+
11+
## Usage
12+
13+
```sh
14+
$ update-lambda-edge --help
15+
```
16+
17+
Help output:
18+
19+
```
20+
update-lambda-edge [command]
21+
22+
Commands:
23+
update-lambda-edge push Pushes a ZIP file containing Lambda code to S3
24+
update-lambda-edge deploy Updates the code of an existing Lambda function
25+
with a new ZIP file in S3
26+
update-lambda-edge publish Publishes a new Lambda version
27+
update-lambda-edge activate Activates the latest versions of Lambda@Edge
28+
functions on specified CloudFront distribution
29+
30+
Options:
31+
--version Show version number [boolean]
32+
--help Show help [boolean]
33+
-r, --region The region that the base Lambdas are running
34+
[string] [default: "us-east-1"]
35+
--dry-run If true, will only print out debug info; it will not update
36+
anything in AWS [boolean]
37+
```
38+
39+
## Available commands
40+
41+
* [push](#push)
42+
* [deploy](#deploy)
43+
* [publish](#publish)
44+
* [activate](#activate)
45+
46+
### push
47+
48+
```sh
49+
$ update-lambda-edge push --help
50+
```
51+
52+
Help output:
53+
54+
```
55+
update-lambda-edge push
56+
57+
Pushes a ZIP file containing Lambda code to S3
58+
59+
Options:
60+
--version Will append this version number to the file name
61+
(ignored if "auto-increment" is true) [string]
62+
--help Show help [boolean]
63+
-r, --region The region that the base Lambdas are running
64+
[string] [default: "us-east-1"]
65+
--dry-run If true, will only print out debug info; it will not
66+
update anything in AWS [boolean]
67+
--bucket The name of the S3 bucket to push the ZIP file to
68+
[string] [required]
69+
--key The file path to the ZIP file in the S3 bucket
70+
[string] [required]
71+
--file-path The relative file path to the ZIP file on local FS
72+
[string] [required]
73+
--function-name If auto-increment is true, this is required to determine
74+
the next Lambda version number [string]
75+
--auto-increment If true, will append the file name with the next Lambda
76+
version [boolean] [default: false]
77+
--pwd Set the present working directory
78+
[string] [default: "/Users/ben.march/Projects/update-lambda-edge"]
79+
```
80+
81+
### deploy
82+
83+
```sh
84+
$ update-lambda-edge deploy --help
85+
```
86+
87+
Help output:
88+
89+
```
90+
update-lambda-edge deploy
91+
92+
Updates the code of an existing Lambda function with a new ZIP file in S3
93+
94+
Options:
95+
--version Will append this version number to the file name
96+
(ignored if "use-next-version" is true) [string]
97+
--help Show help [boolean]
98+
-r, --region The region that the base Lambdas are running
99+
[string] [default: "us-east-1"]
100+
--dry-run If true, will only print out debug info; it will not
101+
update anything in AWS [boolean]
102+
--bucket The name of the S3 bucket where the ZIP file lives
103+
[string] [required]
104+
--key The file path to the ZIP file in the S3 bucket
105+
[string] [required]
106+
--function-name The name of the Lambda function to update
107+
[string] [required]
108+
--use-next-version If true, look for a ZIP file with the next Lambda
109+
version appended to the name[boolean] [default: false]
110+
```
111+
112+
###
113+
114+
```sh
115+
$ update-lambda-edge --help
116+
```
117+
118+
Help output:
119+
120+
```
121+
update-lambda-edge [command]
122+
123+
Commands:
124+
update-lambda-edge push Pushes a ZIP file containing Lambda code to S3
125+
update-lambda-edge deploy Updates the code of an existing Lambda function
126+
with a new ZIP file in S3
127+
update-lambda-edge publish Publishes a new Lambda version
128+
update-lambda-edge activate Activates the latest versions of Lambda@Edge
129+
functions on specified CloudFront distribution
130+
131+
Options:
132+
--version Show version number [boolean]
133+
--help Show help [boolean]
134+
-r, --region The region that the base Lambdas are running
135+
[string] [default: "us-east-1"]
136+
--dry-run If true, will only print out debug info; it will not update
137+
anything in AWS [boolean]
138+
```
139+
140+
### publish
141+
142+
```sh
143+
$ update-lambda-edge publish --help
144+
```
145+
146+
Help output:
147+
148+
```
149+
update-lambda-edge publish
150+
151+
Publishes a new Lambda version
152+
153+
Options:
154+
--version Show version number [boolean]
155+
--help Show help [boolean]
156+
-r, --region The region that the base Lambdas are running
157+
[string] [default: "us-east-1"]
158+
--dry-run If true, will only print out debug info; it will not
159+
update anything in AWS [boolean]
160+
--function-name The name of the Lambda function to publish
161+
[string] [required]
162+
```
163+
164+
### activate
165+
166+
```sh
167+
$ update-lambda-edge activate --help
168+
```
169+
170+
Help output:
171+
172+
```
173+
update-lambda-edge activate
174+
175+
Activates the latest versions of Lambda@Edge functions on specified CloudFront
176+
distribution
177+
178+
Options:
179+
--version Show version number [boolean]
180+
--help Show help [boolean]
181+
-r, --region The region that the base Lambdas are running
182+
[string] [default: "us-east-1"]
183+
--dry-run If true, will only print out debug info; it will not
184+
update anything in AWS [boolean]
185+
-d, --distribution-id The CloudFront distribution ID [string] [required]
186+
--viewer-request The name of the function to be deployed at the Viewer
187+
Request event [string]
188+
--origin-request The name of the function to be deployed at the Origin
189+
Request event [string]
190+
--origin-response The name of the function to be deployed at the Origin
191+
Response event [string]
192+
--viewer-response The name of the function to be deployed at the Viewer
193+
Response event [string]
194+
```
195+
196+
###
197+
198+
```sh
199+
$ update-lambda-edge --help
200+
```
201+
202+
Help output:
203+
204+
```
205+
update-lambda-edge [command]
206+
207+
Commands:
208+
update-lambda-edge push Pushes a ZIP file containing Lambda code to S3
209+
update-lambda-edge deploy Updates the code of an existing Lambda function
210+
with a new ZIP file in S3
211+
update-lambda-edge publish Publishes a new Lambda version
212+
update-lambda-edge activate Activates the latest versions of Lambda@Edge
213+
functions on specified CloudFront distribution
214+
215+
Options:
216+
--version Show version number [boolean]
217+
--help Show help [boolean]
218+
-r, --region The region that the base Lambdas are running
219+
[string] [default: "us-east-1"]
220+
--dry-run If true, will only print out debug info; it will not update
221+
anything in AWS [boolean]
222+
```
223+
224+
## License
225+
226+
MIT.

bin/update-lambda-edge

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env node
2+
3+
const path = require('path')
4+
const yargs = require('yargs/yargs')
5+
const { hideBin } = require('yargs/helpers')
6+
7+
const { pushNewCodeBundle, deployLambda, publishLambda, activateLambdas } = require('../index')
8+
9+
yargs(hideBin(process.argv))
10+
.help()
11+
12+
.command('push', 'Pushes a ZIP file containing Lambda code to S3', yargs => {
13+
yargs
14+
.option('bucket', {
15+
type: 'string',
16+
demandOption: true,
17+
description: 'The name of the S3 bucket to push the ZIP file to'
18+
})
19+
.option('key', {
20+
type: 'string',
21+
demandOption: true,
22+
description: 'The file path to the ZIP file in the S3 bucket'
23+
})
24+
.option('file-path', {
25+
type: 'string',
26+
demandOption: true,
27+
description: 'The relative file path to the ZIP file on local FS'
28+
})
29+
.option('function-name', {
30+
type: 'string',
31+
description: 'If auto-increment is true, this is required to determine the next Lambda version number'
32+
})
33+
.option('auto-increment', {
34+
type: 'boolean',
35+
description: 'If true, will append the file name with the next Lambda version',
36+
default: false
37+
})
38+
.option('version', {
39+
type: 'string',
40+
description: 'Will append this version number to the file name (ignored if "auto-increment" is true)'
41+
})
42+
.option('pwd', {
43+
type: 'string',
44+
description: 'Set the present working directory',
45+
default: process.cwd()
46+
})
47+
}, args => pushNewCodeBundle({
48+
...args,
49+
filePath: path.resolve(args.pwd, args.filePath)
50+
}))
51+
52+
.command('deploy', 'Updates the code of an existing Lambda function with a new ZIP file in S3', yargs => {
53+
yargs
54+
.option('bucket', {
55+
type: 'string',
56+
demandOption: true,
57+
description: 'The name of the S3 bucket where the ZIP file lives'
58+
})
59+
.option('key', {
60+
type: 'string',
61+
demandOption: true,
62+
description: 'The file path to the ZIP file in the S3 bucket'
63+
})
64+
.option('function-name', {
65+
type: 'string',
66+
demandOption: true,
67+
description: 'The name of the Lambda function to update'
68+
})
69+
.option('use-next-version', {
70+
type: 'boolean',
71+
description: 'If true, look for a ZIP file with the next Lambda version appended to the name',
72+
default: false
73+
})
74+
.option('version', {
75+
type: 'string',
76+
description: 'Will append this version number to the file name (ignored if "use-next-version" is true)'
77+
})
78+
}, args => deployLambda(args))
79+
80+
.command('publish', 'Publishes a new Lambda version', yargs => {
81+
yargs
82+
.option('function-name', {
83+
type: 'string',
84+
demandOption: true,
85+
description: 'The name of the Lambda function to publish'
86+
})
87+
}, args => publishLambda(args))
88+
89+
.command('activate', 'Activates the latest versions of Lambda@Edge functions on specified CloudFront distribution', yargs => {
90+
yargs
91+
.option('distribution-id', {
92+
alias: 'd',
93+
type: 'string',
94+
demandOption: true,
95+
description: 'The CloudFront distribution ID'
96+
})
97+
.option('viewer-request', {
98+
type: 'string',
99+
description: 'The name of the function to be deployed at the Viewer Request event'
100+
})
101+
.option('origin-request', {
102+
type: 'string',
103+
description: 'The name of the function to be deployed at the Origin Request event'
104+
})
105+
.option('origin-response', {
106+
type: 'string',
107+
description: 'The name of the function to be deployed at the Origin Response event'
108+
})
109+
.option('viewer-response', {
110+
type: 'string',
111+
description: 'The name of the function to be deployed at the Viewer Response event'
112+
})
113+
}, args => activateLambdas(args))
114+
115+
.option('region', {
116+
alias: 'r',
117+
type: 'string',
118+
description: 'The region that the base Lambdas are running',
119+
default: 'us-east-1'
120+
})
121+
.option('dry-run', {
122+
type: 'boolean',
123+
description: 'If true, will only print out debug info; it will not update anything in AWS'
124+
})
125+
126+
.argv

0 commit comments

Comments
 (0)