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