Skip to content

shogo452/serverless-express-with-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

serverless-express-with-terraform

This repository contains sample code for building AWS infrastructure resources with Terraform using Lambda and API Gateway configuration for an API utilizing serverless-express.

Architecture diagram

The diagram created using pluralith.

project_pluralith-local-project%2Frun_5796186%2Frun_5796186_1707815395710

Directory structure

terraform
β”œβ”€β”€ environments πŸ‘ˆ Environment-specific configuration files
β”‚   β”œβ”€β”€ common
β”‚   β”‚   β”œβ”€β”€ README.md
β”‚   β”‚   β”œβ”€β”€ backend.tf
β”‚   β”‚   β”œβ”€β”€ main.tf
β”‚   β”‚   β”œβ”€β”€ provider.tf
β”‚   β”‚   └── version.tf
β”‚   β”œβ”€β”€ dev
β”‚   β”‚   β”œβ”€β”€ README.md
β”‚   β”‚   β”œβ”€β”€ backend.tf
β”‚   β”‚   β”œβ”€β”€ main.tf
β”‚   β”‚   β”œβ”€β”€ output.tf
β”‚   β”‚   β”œβ”€β”€ provider.tf
β”‚   β”‚   └── version.tf
β”‚   β”œβ”€β”€ prod
β”‚   β”‚   └── README.md
β”‚   └── stg
β”‚       └── README.md
└── modules πŸ‘ˆ Modules for each service
    β”œβ”€β”€ api_gateway
    β”‚   β”œβ”€β”€ README.md
    β”‚   β”œβ”€β”€ main.tf
    β”‚   β”œβ”€β”€ output.tf
    β”‚   β”œβ”€β”€ setting
    β”‚   β”‚   β”œβ”€β”€ main.tf
    β”‚   β”‚   β”œβ”€β”€ output.tf
    β”‚   β”‚   └── variable.tf
    β”‚   └── variables.tf
    β”œβ”€β”€ ec2
    β”‚   β”œβ”€β”€ README.md
    β”‚   β”œβ”€β”€ main.tf
    β”‚   β”œβ”€β”€ output.tf
    β”‚   └── variables.tf
    β”œβ”€β”€ lambda
    β”‚   β”œβ”€β”€ README.md
    β”‚   β”œβ”€β”€ main.tf
    β”‚   β”œβ”€β”€ output.tf
    β”‚   └── variable.tf
    β”œβ”€β”€ rds
    β”‚   β”œβ”€β”€ reader
    β”‚   β”‚   └── README.md
    β”‚   └── writer
    β”‚       β”œβ”€β”€ README.md
    β”‚       β”œβ”€β”€ main.tf
    β”‚       β”œβ”€β”€ output.tf
    β”‚       └── variables.tf
    β”œβ”€β”€ route53
    β”‚   β”œβ”€β”€ README.md
    β”‚   β”œβ”€β”€ main.tf
    β”‚   β”œβ”€β”€ output.tf
    β”‚   └── variables.tf
    β”œβ”€β”€ s3
    β”‚   β”œβ”€β”€ README.md
    β”‚   β”œβ”€β”€ bucket
    β”‚   β”‚   β”œβ”€β”€ main.tf
    β”‚   β”‚   β”œβ”€β”€ output.tf
    β”‚   β”‚   └── variables.tf
    β”‚   └── object
    β”‚       β”œβ”€β”€ latest.zip
    β”‚       β”œβ”€β”€ main.tf
    β”‚       β”œβ”€β”€ output.tf
    β”‚       β”œβ”€β”€ src
    β”‚       β”‚   └── latest.js
    β”‚       └── variables.tf
    └── vpc
        β”œβ”€β”€ README.md
        β”œβ”€β”€ main.tf
        β”œβ”€β”€ output.tf
        └── variables.tf

Additional required resources

The creation of the following resources, which are not managed by this repository, is required separately.

  • S3 Bucket for tfstate file

    • Bucket name like serverless-express-with-terraform-tfstate
  • Sercrets in Secrets Manager

    • master_username
    • master_password
    • port
    • database_name
    • kms_key_id
    • api_key
  • KMS Key for RDS If not already created, please use the following CLI command to create the key.

    aws kms describe-key --key-id alias/aws/rds --region {region-name}

Preparation of access keys

$ vim ~/.aws/credentials

# πŸ‘‡ Add the following
[serverless-express-with-terraform]
aws_access_key_id=xxxxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxx

About

Terraform sample code for a serverless-express-based API.

Topics

Resources

Stars

Watchers

Forks