AWS Lambda functions and API gateway are often used to create serverless applications.
Function code is written in Go and deployed using Terraform.
- Terraform (>= 1.4.3)
- Go (>= 1.19.2)
- AWS CLI (>= 2.12.6)
- AWS Lambda
- API Gateway
- AWS Credentials
- AWS s3
To use Terraform with AWS, you will need to create a user with the appropriate permissions.
The user will need to have the following permissions:
- AWSLambdaFullAccess
- IAMFullAccess
- AmazonAPIGatewayAdministrator
- AmazonS3FullAccess
- CloudWatchLogsFullAccess
Configure the AWS CLI with the credentials of the user you created above.
aws configure
or
export AWS_ACCESS_KEY_ID="anaccesskey"
export AWS_SECRET_ACCESS_KEY="asecretkey"
export AWS_DEFAULT_REGION="us-east-1"
Terraform is an open-source infrastructure as code software tool created by HashiCorp. It enables users to define and provision a datacenter infrastructure using a high-level configuration language known as Hashicorp Configuration Language (HCL), or optionally JSON.
AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers, creating workload-aware cluster scaling logic, maintaining event integrations, or managing runtimes. With Lambda, you can run code for virtually any type of application or backend service - all with zero administration.
Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, CORS support, authorization and access control, throttling, monitoring, and API version management.
build the function binary Go file
make build
terraform init
to initialize a working directory containing Terraform configuration files
terraform init
terraform validate
to validate the configuration files in a directory
terraform validate
terraform plan
to create an execution plan for the changes to be applied
terraform plan
terraform apply
to apply the changes required to reach the desired state of the configuration
terraform apply
After applying the changes, you will see the API Gateway endpoint in the output.
You can use the endpoint to test the API.
terraform output
to inspect the current state
terraform output base_url
Enter the endpoint in your browser or use curl to test the API
curl https://<API_GATEWAY_ENDPOINT>/dev/hello
terraform destroy
to destroy the Terraform-managed infrastructure
terraform destroy
Before opening an issue or pull request, please check the project's contribution documents.
Please read CONTRIBUTING.md for details about our code of conduct, and the process for submitting pull requests.