In this demo, you will learn how to deploy a serverless application made AWS lambda, Amazon API Gateway, and Amazon Aurora Serverless using the AWS Cloud Development Kit, known as the CDK. For a more detailed step-by-step instructions you can follow this blog.
The architecture of this demo consists of AWS Cloud9 instance environment containing a CDK project which deploys an API Gateway and Lambda function. This Lambda function leverages a secret stored in your AWS Secrets Manager to read and write from your Aurora Serverless database through the data API, as shown in the following diagram.
- Clone repo and navigate to directory using the following commands:
git clone https://github.com/aws-samples/aws-cdk-serverless-app-deployment-example.git
cd aws-cdk-serverless-app-deployment-example/RecordsApp
- Configure cdk
sudo yum -y update
nvm install v10.3.0; nvm alias default 10.3.0
npm install -g typescript
npm install -g aws-cdk
cdk init app --language typescript
- Install depedencies
npm install @aws-cdk/aws-apigateway @aws-cdk/aws-lambda @aws-cdk/aws-iam @aws-cdk/aws-rds @aws-cdk/aws-aws-secretsmanager
- Cdk deploy
npm run build; cdk synth; cdk bootstrap; cdk deploy
- Populate db and table
DATABASE NAME : main SECRETS MANAGER: find it in the lambda function environment variables
INSERT INTO singers(id,name,nationality,recordid) VALUES(100,'Michael Jackson','American',001);
- Test
Once it’s done, you can test it using Postman:
GET = ‘RecordName’ in the path
example:
API-GATEWAY ENDPOINT/RecordName
POST = Payload in the body
example:
{
"recordTitle" : "BlogTest",
"recordReleaseDate" : "2020-01-01",
"singerName" : "BlogSinger",
"singerNationality" : "AWS"
}
This library is licensed under the MIT-0 License. See the LICENSE file.