serverless
With latest Node.js 6.x.x installed, then install serverless globally:
1 | $ npm install serverless -g |
AWS Lambda
Create a AWS Lambda skeleton project with serverless:
1 | $ mkdir serverless-example && cd $_ |
- Policies set up for Lambda function
For AWS user “ec2-user”, now need to have some policies with permissions to let “serverless” create role, Lambda function and deployment it …
- Roles for Lambda function
Lambda function role created after Lambda function added and deployed into AWS.
Deployment
Make sure AWS environment has been set up, including access key, user, group, policies …
Pack and deploy Lambda example into AWS:
1 | $ sls deploy -r ap-southeast-2 -s dev |
- Lambda “hello” function
A “hello” Lambda function has been created in Lambda after it’s deployed into AWS by “serverless”.
- Events generated during Lambda function deployment
Deployment events generated during Lambda “hello” function deployed into AWS.
- Add Lambda Trigger on AWS API Gateway
Manually create a Lambda Trigger. This time we use AWS API Gateway to trigger / invoke Lambda “hello” function.
- Exposed Lambda API Gateway
After Lambda Trigger created, an exposed RESTful interface for Lambda “hello” function.
Say “hello”
Set up AWS API Gateway trigger for Lambda “hello” function. Go to url, e.g.:
Function “hello” log:
1 | { |
References
- serverless framework, https://serverless.com/
- Example source code and artefact, https://github.com/TerrenceMiao/AWS/tree/master/serverless-example