Deploy demo app on AWS serverless by utilizing API gateway, python lambda function, and RDS resources
- Install terraform cli terraform on Linux.
- Install AWS CLI AWS CLI
- Terraform Remote State Backend with AWS S3 and DynamoDB How to create a Terraform S3 backend
# terraform workspace new terraform-aws-serverless
# terraform workspace select terraform-aws-serverless
# terraform plan -var-file env/$(terraform workspace show).tfvars
# terraform apply -auto-approve -var-file env/$(terraform workspace show).tfvars
region = "ap-southeast-1"
object_ownership = "BucketOwnerPreferred"
control_object_ownership = true
ami = "ami-066eeae61f083f121"
instance_type = "t2.micro"
db_name = "college"
db_username = "demoapp"
db_password = "<password>"
cognito_user = "<user>"
cognito_password = "<password>"
count_instance = 1
user = "admin"
key_pair_id = "~/.ssh/id_rsa.pub"
Register cognito-idp admin credential permanently using AWS CLI
aws cognito-idp admin-set-user-password --user-pool-id <region endpoint> --username <username> --password <credential> --permanent
To test calling API gateway, first we need to get Bearer access_token from AWS Cognito IDP by using curl command
curl --request POST --url https://cognito-idp.<regions>.amazonaws.com/<region end point> --header 'content-type: application/x-amz-json-1.1' --header 'x-amz-target: AWSCognitoIdentityProviderService.InitiateAuth' --data '{ "AuthParameters" : {"USERNAME" : "<username>", "PASSWORD" : "password"},"AuthFlow" : "USER_PASSWORD_AUTH","ClientId" : "<client ID>"}'
Call AWS Gateway using curl command
curl -X GET https://<rest-api-id>.execute-api.<region>.amazonaws.com/<stage>/ \
-H 'authorization: Bearer <access_token>' \
-H 'content-type: application/json'
Name | Description |
---|---|
API Gateway | AWS API Gateway v2 (HTTP/Websocket) Terraform module |
AWS Lambda | AWS Lambda Terraform module |
AWS RDS | AWS RDS Terraform module |
AWS VPC | AWS VPC Terraform module |
AWS S3 | AWS S3 bucket Terraform module |
MIT / BSD