Simple demo to provision AWS Lambda, APIGateway through Terraform and LocalStack
1st, it's always nice for developers to be able to have a local dev env to test before shipping to the AWS cloud. 2nd reason is AWS will bill you for the APIgateway, so if you only want to play around, by refer to my doc, it will cost you nothing at all. As everything is running on your own computer.
Use the localstack
CLI command to get your local AWS env started:
localstack start -d
# setup aws profile for localstack https://docs.localstack.cloud/user-guide/integrations/aws-cli/#aws-cli
# ~/.aws/config
[profile localstack]
region=us-east-1
output=json
endpoint_url = http://localhost:4566
# ~/.aws/credentials
[localstack]
aws_access_key_id=test
aws_secret_access_key=test
git clone https://github.com/ShengzhenFu/go-lambda-apigateway-terraform.git
cd go-lambda-apigateway-terraform
tfenv install 1.7.4
tfenv use 1.7.4
echo 1.7.4 > .terraform-version
make deploy
This will deploy the AWS ApiGateway integrated with Lambda (Golang) via Terraform. You can check Makefile
for more details
If you see the outputs like below ... 👇 Congratulations, deploy is successful 👍
Let's test the API endpoint. Run below command (replace the apigateway_id with the output you got above)
curl -X POST "http://{apigateway_id}.execute-api.localhost.localstack.cloud:4566/local/api?name=Localstack" -H "content-type: application/json"
If your result is like below, then congratulations ! it works as expected.
you could also use tools like POSTMAN to test it.
make destroy
localstack stop
- CDK implementation
- CI/CD CodePipeline
- Make a more practical demo of Golang project