GithubHelp home page GithubHelp logo

aws-fargate-example's Introduction

aws-fargate-example

This is a practical example to launch a service on AWS Fargate.

Prerequisites

$ aws --version
aws-cli/1.16.193 Python/3.7.3 Darwin/18.6.0 botocore/1.12.183
$ ecs-cli --version
ecs-cli version 1.14.1 (f73f9e3)
$ terraform version
Terraform v0.12.3

Launch services on Fargate

First, create your S3 bucket by AWS CLI to store your tfstate file. You can specify <BUCKET_NAME> as you like.

$ aws --profile dev s3api create-bucket --bucket <BUCKET_NAME> --acl private --create-bucket-configuration LocationConstraint=ap-northeast-1

Then, apply Terraform to create a Fargate cluster. It takes a while to create RDS instance and ElastiCache cluster.

$ cd terraform
$ terraform init
$ terraform apply
var.cidr_office
  CIDR allowed connecting to resources, like your office's IP

  Enter a value: x.x.x.x/32

var.owner
  Owner name of resources

  Enter a value: your.name

var.s3_bucket_name
  Your S3 bucket name

  Enter a value: your-s3-bucket-name
...

And apply Terraform again to create a PostgreSQL database. It's needed to separate directories to avoid the postgresql provider issue. hashicorp/terraform-provider-postgresql#2

$ cd terraform/postgresql
$ terraform init
$ terraform apply
var.db_root_password
  RDS root password

  Enter a value: db_root_pasword

var.owner
  Owner name of resources

  Enter a value: your.name
...

After that, you need to prepare the file ecs-params.yml. You can use a script to generate the file as bellow. Please note that the script depends on envsubst.

$ ./generate-ecs-params.sh
ecs-params.yml was generated.

Finally, deploy Redash service to the Fargate cluster. Please set <TARGET_GROUP_ARN> and <OWNER> correctly, the owner tag is just a metadata though.

$ ecs-cli compose --aws-profile dev --cluster dev-fargate --project-name redash service up --launch-type FARGATE --target-group-arn <TARGET_GROUP_ARN> --container-name server --container-port 5000 --tags Owner=<OWNER>

Verify services and monitoring

TBD

Destroy resources

If you want to destroy all resources of this example, please follow the steps below.

Delete the Redash service on Fargate cluster by ECS CLI.

$ ecs-cli compose --aws-profile dev --cluster dev-fargate --project-name redash service down

Delete the PostgreSQL database by Terraform. Some error may occur but you can ignore it and remove the state if you also destroy the RDS instance. hashicorp/terraform-provider-postgresql#36

$ cd terraform/postgresql
$ terraform destroy
...
Error: Error deleting role: pq: permission denied to reassign objects


$ terraform state rm postgresql_role.redash
$ terraform destroy

Destroy the remaining resources by Terraform. It takes a while to delete RDS instance and ElastiCache cluster.

$ cd terraform
$ terraform destroy

Furthermore, if you want to delete the S3 bucket you created, please execute the following command. <BUCKET_URL> is like s3://bucket-name.

$ aws --profile dev s3 rb <BUCKET_URL> --force

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.