1 |
|
2 |
|
3 | # cli-lambda-deploy
|
4 | Command line tool deploy code to [AWS Lambda](http://aws.amazon.com/lambda/).
|
5 |
|
6 | [![Build Status](https://travis-ci.org/awspilot/cli-lambda-deploy.svg?branch=master)](https://travis-ci.org/awspilot/cli-lambda-deploy)
|
7 | [![Downloads](https://img.shields.io/npm/dm/aws-lambda?maxAge=2592000)](https://www.npmjs.com/package/aws-lambda)
|
8 | [![Downloads](https://img.shields.io/npm/dy/aws-lambda?maxAge=2592000)](https://www.npmjs.com/package/aws-lambda)
|
9 | [![Downloads](https://img.shields.io/npm/dt/aws-lambda?maxAge=2592000)](https://www.npmjs.com/package/aws-lambda)
|
10 |
|
11 |
|
12 | ## Installation
|
13 |
|
14 | ```
|
15 | npm install -g aws-lambda
|
16 | ```
|
17 |
|
18 | WARN: upgrading to v1.0.0 will remove your function environment and layers if they are not defined in the config file
|
19 |
|
20 | ## Config file
|
21 |
|
22 | * PATH must point to your code folder and is relative to the config file
|
23 | * PATH can be relative or absolute
|
24 | * If not set, Runtime defaults to **nodejs10.x**
|
25 | * If not set, FunctionName defaults to the name of the config file ("my-function" in this case)
|
26 | * You can use **Ref** to reference environment variables in the form of env.YOUR_ENVIRONMENT_NAME
|
27 | * `lambda deploy <file.lambda>` credentials needs permissions to **CreateFunction**, **UpdateFunctionConfiguration** and **UpdateFunctionCode**
|
28 | * `lambda delete <file.lambda>` credentials needs permissions to **DeleteFunction**
|
29 | * `lambda invoke <file.lambda>` credentials needs permissions to **InvokeFunction**
|
30 |
|
31 |
|
32 | ## Sample JSON config
|
33 |
|
34 | ```
|
35 |
|
36 | {
|
37 | "PATH": "./test-function",
|
38 | "AWS_KEY": { "Ref" : "env.AWS_ACCESS_KEY_ID" },,
|
39 | "AWS_SECRET": { "Ref" : "env.AWS_SECRET_ACCESS_KEY"},
|
40 | "AWS_REGION": "us-east-1",
|
41 |
|
42 | "FunctionName": "test-lambda",
|
43 | "Role": "your_amazon_role",
|
44 | "Runtime": "nodejs10.x",
|
45 | "Handler": "index.handler",
|
46 | "MemorySize": "128",
|
47 | "Timeout": "3",
|
48 | "Environment": {
|
49 | "Variables": {
|
50 | "Hello": "World",
|
51 | }
|
52 | },
|
53 | "Layers": [
|
54 | "arn:aws:lambda:eu-central-1:452980636694:layer:awspilot-dynamodb-2_0_0-beta:1"
|
55 | ],
|
56 | "Tags": {
|
57 | "k1": "v1",
|
58 | "k2": "v2"
|
59 | },
|
60 | "Description": ""
|
61 | }
|
62 | ```
|
63 |
|
64 | ## Sample YAML config
|
65 |
|
66 | ```
|
67 | # unlike json, comments are allowed in yaml, yey!
|
68 | # remember to use spaces not tabs 😞
|
69 | PATH: ./new-function
|
70 | AWS_KEY: !Ref "env.lambda_deploy_aws_key"
|
71 | AWS_SECRET: !Ref "env.lambda_deploy_aws_secret"
|
72 | AWS_REGION: "eu-central-1"
|
73 |
|
74 | FunctionName: new-function-v12
|
75 | Role: "arn:aws:iam::452980636694:role/CliLambdaDeploy-TestRole-1H89NZ845HHBK"
|
76 | Runtime: "nodejs8.10"
|
77 | Handler: "index.handler"
|
78 | MemorySize: "128"
|
79 | Timeout: "3"
|
80 | Environment:
|
81 | Variables:
|
82 | Hello: "World"
|
83 | Layers:
|
84 | - "arn:aws:lambda:eu-central-1:452980636694:layer:awspilot-dynamodb-2_0_0-beta:1"
|
85 | Tags:
|
86 | k1: v1
|
87 | k2: v2
|
88 | Description: ""
|
89 | ```
|
90 |
|
91 |
|
92 |
|
93 | ## Deploy from Local to AWS Lambda
|
94 |
|
95 | ```
|
96 | // if installed globally then
|
97 | $ lambda deploy /path/to/my-function.lambda
|
98 | $ lambda deploy ../configs/my-function.lambda
|
99 |
|
100 | // if 'npm installed' without the -g then you must use the full path
|
101 | $ node_modules/.bin/lambda /path/to/my-function.lambda
|
102 |
|
103 | // you can also add it in your scripts section of your package.json scripts: { "deploy-func1": "lambda deploy ../config/func1.lambda" }
|
104 | $ npm run deploy-func1
|
105 | ```
|
106 |
|
107 | ## Watch config file
|
108 |
|
109 | aws-lambda can also watch the config file and the code folder specified in the config.PATH for changes and re-reploy on change
|
110 |
|
111 | ```
|
112 | $ lambda start ../configs/my-function.lambda
|
113 | ```
|