AWS Lightsail microservice deployed to AWS Lambda and API Gateway.
The pipeline is a full CI/CD serverless pipeline for building and deploying lambda function and api. In this application we are using CloudFormation to create the pipeline, all resources, and any permissions needed.
The following resources are created:
- An S3 bucket to store deployment artifacts.
- An AWS CodeBuild stage to build any changes checked into the repo.
- The AWS CodePipeline that will watch for changes on your repo, and push these changes through to build and deployment steps.
- All IAM roles and policies required.
The CloudFormation templates being used to create these resources can be found in pipeline directory.
To create the pipeline stack, click the launch stack button below.
The Serverless API we are building! The api section contains five files.
- beta.json: The CloudFormation staging file. This will be used by CloudFormation to pass parameters to our CloudFormation template.
- buildspec.yml: This is used by CodeBuild in the build step of our pipeline. We will get to that later.
- index.js: The Lambda function code!
- package.json: The package.json that defines what packages we need for our Lambda function.
- template.yaml: This is the template file that will be used to create our API gateway resource, Lambda function and hook them up together
The service requires the following GET query strings:
action
- The required actionreference
- The instance name
Request:
GET /lightsail?action=start&reference=WordPress-512MB-Sydney-TEST HTTP/1.1
Content-Type: application/x-www-form-urlencoded
GET /lightsail?action=stop&reference=WordPress-512MB-Sydney-TEST HTTP/1.1
Content-Type: application/x-www-form-urlencoded
GET /lightsail?action=status&reference=WordPress-512MB-Sydney-TEST HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Response:
HTTP/1.1 200 OK
{
"id": "43684203-f9fe-4e0b-acdf-9e4eae3dff18",
"CurrentState": "stopping",
}
{
"CurrentState": "stopped",
}