@harryhope/fdeploy 1.0.0
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.
- package/LICENSE +9 -0
- package/README.md +25 -0
- package/index.js +81 -0
- package/package.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Harry Hope
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# fdeploy
|
|
2
|
+
A simple CLI-tool for deploying Lambdas.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
```
|
|
6
|
+
fdeploy <command>
|
|
7
|
+
|
|
8
|
+
Commands:
|
|
9
|
+
fdeploy lambda Deploy a lambda function to AWS [aliases: l]
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
--version Show version number [boolean]
|
|
13
|
+
--help Show help [boolean]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
To use `fdeploy`, open a terminal window in your Lambda function's folder.
|
|
17
|
+
|
|
18
|
+
`fdeploy` uses [dotenv](https://www.dotenv.org) to read AWS keys from your project's folder. By default it will read `ACCESS_KEY_ID` and `SECRET_ACCESS_KEY` environment variables. They must corrispond to an IAM key that has Lambda deployment access.
|
|
19
|
+
|
|
20
|
+
A simple deployment command may look like:
|
|
21
|
+
```
|
|
22
|
+
fdeploy lambda -n your-lambda-name
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Running this command from a folder containing your Lambda's code will zip and upload the file to AWS and deploy it as a Lambda function named `your-lambda-name`.
|
package/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { Lambda } = require('@aws-sdk/client-lambda')
|
|
3
|
+
const AdmZip = require('adm-zip')
|
|
4
|
+
const dotenv = require('dotenv')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const yargs = require('yargs/yargs')
|
|
7
|
+
const { hideBin } = require('yargs/helpers')
|
|
8
|
+
|
|
9
|
+
const deploy = async (funcName, dir, region) => {
|
|
10
|
+
const folder = path.resolve(dir || process.cwd())
|
|
11
|
+
const envPath = path.resolve(dir || process.cwd(), '.env')
|
|
12
|
+
|
|
13
|
+
dotenv.config({ path: envPath })
|
|
14
|
+
|
|
15
|
+
const ora = await import('ora')
|
|
16
|
+
const chalk = (await import ('chalk')).default
|
|
17
|
+
const spinner = ora.default('Zipping folder').start()
|
|
18
|
+
|
|
19
|
+
if (!funcName || !folder) {
|
|
20
|
+
throw new Error('You must provide the function name and folder to zip')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const zip = new AdmZip()
|
|
24
|
+
zip.addLocalFolder(folder)
|
|
25
|
+
|
|
26
|
+
zip.toBuffer(buffer => {
|
|
27
|
+
spinner.text = 'Uploading to Lambda'
|
|
28
|
+
const lambda = new Lambda({
|
|
29
|
+
region,
|
|
30
|
+
credentials: {
|
|
31
|
+
accessKeyId: process.env.ACCESS_KEY_ID,
|
|
32
|
+
secretAccessKey: process.env.SECRET_ACCESS_KEY
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const params = {
|
|
37
|
+
FunctionName: funcName,
|
|
38
|
+
Publish: true,
|
|
39
|
+
ZipFile: buffer
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
lambda.updateFunctionCode(params, (err, data) => {
|
|
43
|
+
spinner.stop()
|
|
44
|
+
if (err) {
|
|
45
|
+
console.error(err)
|
|
46
|
+
console.log()
|
|
47
|
+
console.log(chalk.bgRed.bold(`Failed to deploy ${funcName}`))
|
|
48
|
+
} else {
|
|
49
|
+
console.log(data)
|
|
50
|
+
console.log()
|
|
51
|
+
console.log(chalk.bgGreen.bold(`${funcName} deployed successfully`))
|
|
52
|
+
console.log()
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
yargs(hideBin(process.argv))
|
|
59
|
+
.command(
|
|
60
|
+
['lambda', 'l'],
|
|
61
|
+
'Deploy a lambda function to AWS',
|
|
62
|
+
{
|
|
63
|
+
directory: {
|
|
64
|
+
alias: 'd',
|
|
65
|
+
describe: 'The directory to zip and deploy'
|
|
66
|
+
},
|
|
67
|
+
name: {
|
|
68
|
+
alias: 'n',
|
|
69
|
+
describe: 'The name of the lambda function'
|
|
70
|
+
},
|
|
71
|
+
region: {
|
|
72
|
+
alias: 'r',
|
|
73
|
+
describe: 'The AWS region to deploy the lambda to',
|
|
74
|
+
default: 'us-east-1'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
argv => { deploy(argv.name, argv.directory, argv.region)}
|
|
78
|
+
)
|
|
79
|
+
.help()
|
|
80
|
+
.demandCommand(1, 'Enter a command from the list above')
|
|
81
|
+
.parse()
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@harryhope/fdeploy",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI for deploying AWS Lambda functions",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"fdeploy": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"author": "Harry Hope",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@aws-sdk/client-lambda": "^3.554.0",
|
|
16
|
+
"adm-zip": "^0.5.12",
|
|
17
|
+
"chalk": "^5.3.0",
|
|
18
|
+
"dotenv": "^16.4.5",
|
|
19
|
+
"ora": "^8.0.1",
|
|
20
|
+
"yargs": "^17.7.2"
|
|
21
|
+
}
|
|
22
|
+
}
|