You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-21Lines changed: 35 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,11 @@
4
4
5
5
[](https://travis-ci.org/irvinlim/es2017-lambda-boilerplate)[](https://greenkeeper.io/)[](https://github.com/irvinlim/es2017-lambda-boilerplate/releases)[](http://opensource.org/licenses/MIT)
6
6
7
-
This is a boilerplate for [AWS Lambda](https://aws.amazon.com/lambda/) Node.js 6.10.0 functions, which allows you to use the latest JavaScript [ES2017/ES8 features](https://hackernoon.com/es8-was-released-and-here-are-its-main-new-features-ee9c394adf66) within a Lambda function.
7
+
This is a boilerplate for [AWS Lambda](https://aws.amazon.com/lambda/) Node.js 6.10.0 functions, which allows you to use the latest JavaScript [ES2017/ES8 features](https://hackernoon.com/es8-was-released-and-here-are-its-main-new-features-ee9c394adf66). The boilerplate also allows you to test your function in a Docker container (thanks to [docker-lambda](https://github.com/lambci/docker-lambda)), and also includes common configurations for CI/CD, for both [Travis CI](https://travis-ci.org/) and [AWS CodeBuild](https://aws.amazon.com/codebuild/) + [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
8
8
9
-
This boilerplate adds support for the following most commonly used JavaScript features that are not natively supported on AWS Lambda:
9
+
## ES2017 features
10
+
11
+
This boilerplate adds support for the following most commonly used JavaScript features that are not natively supported on Node.js 6.10:
_Note: Only features which are not normally available on AWS Lambda Node.js 6.10.0 are listed. Most ES2015/ES6 features and earlier are supported._
25
+
_Note: Most ES2015/ES6 are earlier features are supported._
24
26
25
27
## Usage
26
28
27
29
Edit your Lambda function under `src/main.js`, and run:
28
30
29
31
```sh
30
-
npm run package
32
+
npm run build
31
33
```
32
34
33
-
This will create an `artifact.zip` file which you can upload to AWS Lambda.
35
+
This will transpile your functions down to ES5 using Babel, so that it can be executed using the Node.js 6.10.0 runtime.
36
+
37
+
For convenience, the following command will create an `artifact.zip` file which you can upload to AWS Lambda:
38
+
39
+
```sh
40
+
npm run package
41
+
```
34
42
35
43
## Testing
36
44
@@ -40,9 +48,9 @@ You can run automated tests for your Lambda function inside of a Docker containe
40
48
npm run test
41
49
```
42
50
43
-
The test runner used is [Jest](https://github.com/facebook/jest) (with [Jasmine](https://jasmine.github.io)). All files in the `test/` directory which end with `.test.js` will be interpreted as a test suite.
51
+
All files in the `test/` directory which end with `.test.js` will be interpreted as a test suite. A sample unit test is provided under [test/example.test.js](https://github.com/irvinlim/es2017-lambda-boilerplate/blob/master/test/example.test.js) to get you started.
44
52
45
-
This also requires Docker to be installed on your host; see the [docs for docker-lambda](https://github.com/lambci/docker-lambda) for more instructions.
53
+
The test runner used is [Jest](https://github.com/facebook/jest) (with [Jasmine](https://jasmine.github.io)). Using docker-lambda also requires Docker to be installed on your host; see the [docs for docker-lambda](https://github.com/lambci/docker-lambda) for more instructions.
46
54
47
55
### Specification tests
48
56
@@ -57,21 +65,21 @@ If you are not going to modify `.babelrc`, you can choose to skip these tests by
57
65
58
66
## Deployment
59
67
60
-
### Deployment through AWS SDK
68
+
### Deployment using the AWS SDK
61
69
62
-
You can automatically deploy to AWS Lambda locally or through CI (e.g. Travis) using the AWS SDK, as long as you provide an access key for an IAM user that has write access to AWS Lambda. A single NPM script allows you to deploy using this method:
70
+
You can automatically deploy to AWS Lambda locally or through CI (e.g. Travis CI) using the AWS SDK, as long as you provide an access key for an IAM user that has write access to AWS Lambda. A single NPM script allows you to deploy using this method:
63
71
64
72
```sh
65
73
npm run deploy
66
74
```
67
75
68
-
See [Environment variables](#environment-variables) for the list of environment variables that are required for deployment.
76
+
See [Environment variables](#environment-variables) for the list of environment variables that are required for SDK deployment.
69
77
70
78
### Deployment through CloudFormation + CodeBuild
71
79
72
-
Instead of depending on external tools like Travis, you can also choose to use [AWS CloudFormation](https://aws.amazon.com/cloudformation/) to bootstrap the relevant AWS resources, integrated with [AWS CodeBuild](https://aws.amazon.com/codebuild/) and [AWS CodePipeline](https://aws.amazon.com/codepipeline/). Alternatively, deployment via [AWS CodeStar](https://aws.amazon.com/codestar/)might also be supported out of the box.
80
+
Instead of depending on external tools like Travis CI, you can also choose to use [AWS CloudFormation](https://aws.amazon.com/cloudformation/) to bootstrap the relevant AWS resources, integrated with [AWS CodeBuild](https://aws.amazon.com/codebuild/) and [AWS CodePipeline](https://aws.amazon.com/codepipeline/). Alternatively, deployment via [AWS CodeStar](https://aws.amazon.com/codestar/)may also be supported out of the box.
73
81
74
-
To modify the build process, you can update the CodeBuild configuration file at [`buildspec.yml`](https://github.com/irvinlim/es2017-lambda-boilerplate/blob/master/buildspec.yml), or to modify any Lambda properties, you can update the CloudFormation configuration file at [`samTemplate.yml`](https://github.com/irvinlim/es2017-lambda-boilerplate/blob/master/samTemplate.yml).
82
+
To modify the build process, you can update the CodeBuild configuration file at [`buildspec.yml`](https://github.com/irvinlim/es2017-lambda-boilerplate/blob/master/buildspec.yml). To modify the properties of the resultant Lambda function, you can update the CloudFormation configuration file at [`samTemplate.yml`](https://github.com/irvinlim/es2017-lambda-boilerplate/blob/master/samTemplate.yml).
75
83
76
84
If you are new to AWS CI/CD tools, you can follow the official [AWS tutorial](http://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html) to set up a build pipeline using CodePipeline. Take note of the following:
77
85
@@ -86,24 +94,30 @@ You can write Lambda functions that make use of the [AWS SDK](https://github.com
86
94
87
95
Also make sure that your function has Internet connectivity (i.e. not within a VPC without a NAT gateway). The `internetConnectivityTest.js` utility is included to help to debug such problems early when deploying to AWS Lambda.
88
96
89
-
## Environment variables
97
+
###Environment variables
90
98
91
-
The following environment variables are supported:
99
+
If you plan to use the AWS SDK, either for deployment (using `npm run deploy`), or within your function itself, you need to pass the following environment variables:
92
100
93
101
*`AWS_ACCESS_KEY_ID`: IAM user access key ID
94
102
*`AWS_SECRET_ACCESS_KEY`: IAM user secret access key
95
-
*`AWS_REGION`: AWS region where the Lambda function resides in
96
-
*`LAMBDA_FUNCTION_NAME`: Name or ARN of the Lambda function
103
+
*`AWS_REGION`: AWS region where the Lambda function resides in (_required for SDK deployment only_)
104
+
*`LAMBDA_FUNCTION_NAME`: Name or ARN of the Lambda function (_required for SDK deployment only_)
97
105
98
-
This will work if you store it in a `.env` file in the root of the project (see [dotenv](https://github.com/motdotla/dotenv)), or if you define it within Travis CI itself (see [Travis docs](https://docs.travis-ci.com/user/environment-variables/)).
106
+
This will work if you store it in a `.env` file in the root of the project (see [dotenv](https://github.com/motdotla/dotenv)), or if you define it within Travis CI itself (see [Travis CI docs](https://docs.travis-ci.com/user/environment-variables/)).
99
107
100
-
## Why?
108
+
### IAM user permissions
109
+
110
+
The minimum permissions required for the IAM user for SDK deployment are:
Remember to add more permissions as required if you need to access the SDK in your function.
115
+
116
+
## Why?
103
117
104
-
Even though Lambda supposedly supports Node.js 6.10.0, not all JavaScript features are supported. [www.whatdoeslambdasupport.com](http://www.whatdoeslambdasupport.com/) has a comprehensive list of what is supported and what are not.
118
+
### Latest ES2017/ES2016 features
105
119
106
-
This boilerplate adds support for the most commonly used features that are not available on Node 6.10.0 or AWS Lambda, such as `async`/`await` when used with the [AWS SDK](https://github.com/aws/aws-sdk-js):
120
+
The highest version of Node.js supported on AWS Lambda is 6.10.0, which supports only features up to ES2015/ES6. Newer features in ES2017, such as `async`/`await`, are incredibly useful when performing network requests, such as when used with the [AWS SDK](https://github.com/aws/aws-sdk-js):
0 commit comments