Skip to content

HelloWorld Serverless

Iain Hunter edited this page Sep 9, 2019 · 9 revisions

The helloWorld app demonstates how we can upload a docker container to AWS and run it on a cron-like schedule

Setting up the global environment

1. Creating a global VPC

We can create our VPC by running the following:

cd /ops/terraform/global/vpc
tfinit
terraform apply

2. Creating IAM Credentials

Our app is going to need permissions to setup and use our serverless infrastructure on Amazon Fargate, here we just create the necessary roles and policies

cd /ops/terraform/global/iam
tfinit
terraform apply

Setting up the HelloWorld app

3. Setup the Serverless Environment

We now need to create the infrastructure for our app to sit on

cd /ops/terraform/apps/fargate_hello
tfinit
terraform apply

4. Building our container

5. Manually pushing up our container

Finally we need to push our container to the cloud:

  • The output of Step 3 will include the URL of the ECR repo eg YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/fargate-hello
  • You now need to tag the local fargate-hello container using a special format so it can be uploaded to AWS:
  • docker tag fargate_hello:latest YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/fargate-hello:latest
  • From the terraform container we need to get a login so we can push the container to AWS:
  • aws ecr get-login --no-include-email
  • Copy and paste the output and run it on the command line we can login to AWS ECR
  • Finally we can push the image to AWS
  • docker push YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/fargate-hello:latest

6. Destroying our app when we're finished

We can remove all infrastructure by running the following

cd /ops/terraform/apps/fargate_hello
terraform destroy
cd /ops/terraform/global/iam
terraform destroy
cd /ops/terraform/global/vpc
terraform destroy