For more details about Serverless Framework, please check the official documentation.
- Install serverless framework globally
$ npm i -g serverless
-
Install aws-cli, follow the official guide
-
Setup Serverless with aws-cli
$ serverless config credentials --provider aws --key <ACCESS KEY> --secret <SECRET ACCESS KEY>
- Install all dependencies
$ npm install
.
├── configs (configuration folder)
├── modules (modules folder)
│ └── sns (module / context)
│ ├── endpoints (API endpoints)
│ │ ├── create.js
│ │ ├── delete.js
│ │ ├── read.js
│ │ └── update.js
│ └── functions (workers / background functions)
├── package.json
├── serverless.yml (serverless config)
├── handlers (functions config)
│ ├── sns-endpoints.yml (endpoints config)
├── shared (shared components)
│ └── lib (shared libraries)
│ ├── kinesis.js
│ ├── lambda.js
│ ├── parsers.js
│ ├── sqs.js
│ └── uuid.js
functions:
# API Endpoints
sns-types:
handler: modules/sns/endpoints/read.list #Path to function
memorySize: 128 # Lambda Memory Limit
timeout: 30 # Lambda Timeout
events:
- http: # HTTP Trigger
path: member/sns
method: get
integration: lambda
# Requires clients to add API keys values in the `x-api-key` header of their request
# private: true
This boilerplate uses serverless-local plugin and some containers and plugins to emulate the AWS Resources
docker-compose upThe applications will start on http://localhost:3000
This boilerplate contains following plugins for local development:
- serverless-offline - For run API Gateway local and manage plugins
serverless deploy --stage ${dev or prod}serverless deploy function -f sns-typesserverless sns-types -f bananinha -tserverless removeList of SNS kinds
curl -X GET \
${sns-types lambda endoint}Creating and Using custom variables to build dynamic name
custom:
secrets: ${file(./configs/${self:provider.stage}.json)}Building URL Resources using CloudFormation parameters and Custom Variables
#Global Environment variables
environment:
RDS_DATABASE: ${self:custom.secrets.RDS_DATABASE}
RDS_HOSTNAME: ${self:custom.secrets.RDS_HOSTNAME}
RDS_PASSWORD: ${self:custom.secrets.RDS_PASSWORD}
RDS_USERNAME: ${self:custom.secrets.RDS_USERNAME} # Instruct Serverless to use an existing IAM role for all Lambda functions
iam:
role: ${self:custom.secrets.EXECUTION_ROLE}
#deploymentRole: ${self:custom.secrets.DEPLOYMENT_ROLE}Manage Infrastructure Components - Docs
# Infrastrucure - Cloud Formation
resources: # CloudFormation template syntaxConfigure the Lambda functions to run inside a VPC VPC docs
# If you use VPC then both securityGroupIds and subnetIds are required
vpc:
securityGroupIds:
- ${self:custom.secrets.SECURITY_GROUP_ID}
subnetIds:
- ${self:custom.secrets.SUBNET1_ID}
- ${self:custom.secrets.SUBNET2_ID}