A reference project to deploy a React app onto Amazon ECS on AWS Fargate, and Amazon Elasticsearch Service with Terraform
A todo app fetching data from Amazon Elasticsearch Service
- Make sure you have installed Terraform, AWS CLI, and configured a
default
AWS CLI profile (see doc here)
terraform -help # prints Terraform options
which aws # prints /usr/local/bin/aws
aws --version # prints aws-cli/2.0.36 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0
aws configure # configure your AWS CLI profile
-
Create a Github project, and generate a personal access token (see doc here)
-
Create an S3 bucket to store Terraform state. Populate bucket name in
01-main.tf
- Create a secret on AWS Secrets Manager named
DockerHubAccessToken
with keyDOCKER_HUB_ACCESS_TOKEN
, and your Docker access token as value
- Populate
terraform.tfvars
:
default_region = "us-east-1"
docker_username = "matlau"
github_username = "MatthewCYLau"
github_project_name = "aws-react-elasticsearch-terraform"
app_name = "aws-elasticsearch-app"
environment = "staging"
upload_bucket_name = "matlau-s3-es-upload"
-
Create an S3 bucket to store your Lambda function packages
-
Navigate to
/deploy/lambdas/<FUNCTION_NAME>
-
Update the
deploy/lambdas/<FUNCTION_NAME>/updateFunction.sh
shell script with correct values i.e. Amazon S3 bucket name, and key. See documentation on AWS CLIupdate-function-code
here -
Run the script:
sh deploy/lambdas/<FUNCTION_NAME>/updateFunction.sh
Note, you may encounter Function not found
error the first time running the script
cd deploy # change to deploy directory
terraform init # initialises Terraform
terraform apply # deploys AWS stack. See output for AWS loadbalancer DNS name
terraform destroy # destroys AWS stack
When prompted for github_token
, provide the value and hit Return. Alternatively, create a local environment variable named TF_VAR_github_token
- Upload
deploy/lambdas/processS3Upload/data.csv
to theupload_bucket_name
S3 bucket to trigger Lambda - Then, visit app at
aws_lb_dns_name
to view todos
- Run
docker-compose up
to build, and run app in container
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
If you find this project helpful, please give a ⭐ or even better buy me a coffee ☕ 👇 because I'm a caffeine addict 😅