- Để test SAM application serverless, cloudformation. Phục vụ mục đích học tập
Các mục kiến thức cần lưu ý
- Cloud formation + SAM deploy and package serverless
- Dùng AWS::CloudFormation::CustomResource để khi deploy sẽ change base url (của API Gateway) vào trong file index.html của s3 bucket
-
check exist index curl ES_DOMAIN/_aliases curl ES_DOMAIN/_cat/indices?v
-
check mapping curl ES_DOMAIN/item
-
check item curl ES_DOMAIN/item/_search
The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Python 3 installed
- Docker - Install Docker community edition
To build and deploy your application for the first time, run the following in your shell:
sam build --use-container
sam deploy --guided
Build your application with the sam build --use-container
command.
sam-bom1$ sam build --use-container
sam local invoke HelloWorldFunction --event events/event.json
The SAM CLI can also emulate your application's API. Use the sam local start-api
to run the API locally on port 3000.
sam local start-api
http://localhost:3000/
sam logs -n HelloWorldFunction --stack-name sam-bom1 --tail
To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
aws cloudformation delete-stack --stack-name sam-bom1