Ở phần này thì mình sẽ hướng dẫn các bạn sử dụng terraform để tự động tạo hệ thống
Download CLI tại link. Sau đó thì kiểm tra bằng lệnh:
terraform --version
Cài đặt AWS CLI tại link. Và kiểm tra tại
aws --version
Bạn có thể sử dụng tài liệu này để setup credentials cho CLI link
Cài đặt SAM CLI để build source: link
sam --version
Tiếp theo là bạn cần nvm để cài đặt nodejs và esbuild link
# Validate nvm
nvm -v
# Install nodejs with latest version (Listing version with `nvm ls` or specified version `nvm install 20 && nvm use 20`)
nvm install node && nvm use node
# Validate nodejs is installed
node -v
# Install esbuild global
npm install -g esbuild
Region is us-east-1
.
Đây là cấu trúc thư mục chính, mục đích là để sử dụng lại khi cần
.
├── README.md
├── main.tf
├── modules
│ ├── amazon-bedrock
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── providers.tf
│ │ └── variables.tf
│ ├── cloudwatch
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── dynamodb
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── iam-role
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── lambdas
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── s3
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── ses
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ └── sqs
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── outputs.tf
├── providers.tf
├── terraform.tfvars.example (You must copy and edit this file to `terraform.tfvars`)
└── variables.tf
Đầu tiên thì bạn cần clone hoặc download source code tại link. Sau đó thì bạn copy thư mục resource vào nơi khác.
Tiếp theo, ở thư mục terraform
bạn cần copy file terraform.tfvars.example
thành terraform.tfvars
. File này giống như .env trong NodeJS và sẽ chứa các nội dung như sau
Vào thư mục terraform
cd terraform
Init Provider
terraform init
Kiểm tra state hiện tại và cú pháp
terraform plan
Nếu không có lỗi thì bạn có thể tiếp tục.
terraform apply -auto-approve
Sau bước này thì bạn cần vào SES để setup DKIM 4 Setting Domain and Email identity. Sau khi xong thì bạn đã có thể testing hệ thống của mình.
terraform destroy -auto-approve