Skip to content

Latest commit

 

History

History
104 lines (85 loc) · 6.48 KB

deployment.md

File metadata and controls

104 lines (85 loc) · 6.48 KB

Deployment instructions

In order to get the application running in AWS ECS you will need:

  • Create an AWS ECR repositories in single region of choice
  • Push the application images to the ECR repositories
  • Create the stack of necessary AWS resources to set up and run the application
  • Set up AWS Route 53 to route client requests to the running application

These step are discussed in details in the following subsections.

Create ECR repositories

Create ECR repositories named prebid/pbjs-bundle-service-api and prebid/pbjs-bundle-service-builder (these are the names of the docker images).

When repositories are created note the name of the repositories in form <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-api. They will be needed during the next steps.

Push images to ECR repositories

Given that the application images are already generated locally and ECR repositories exist it's time to push them to the repositories to make them available for deployment.

In order to be able to push to repositories you must log in into ECR first. In order to do that run the following commands (it will require AWS credentials set up properly):

$(aws ecr get-login --no-include-email)

After that you will be able to push the images to corresponding repositories:

docker tag prebid/pbjs-bundle-service-api:latest <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-api:latest
docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-api:latest

docker tag prebid/pbjs-bundle-service-builder:latest <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-builder:latest
docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-builder:latest

After this step you should be able to see the images in ECR in AWS Console.

Create AWS resources and deploy application

In order to get application deployed to AWS ECS many different AWS-specific resources should be created, most important among them: VPC, Subnets, Application Load Balancer, ECS cluster, ECS Task Definition and ECS Service.

This project contains AWS CloudFormation templates allowing to create all these resource easily with a few clicks. These templates are located in cloudformation directory.

All the resources are broken into three groups. First group contains all the network resources (VPC, Subnets) and ECS Cluster. Second group contains ECS Task Definition, Service, Auto Scaling Group and ALB. Third group contains Lambda functions and DynamoDB table.

In order to start the process of resources creation using these templates they should be stored in S3 bucket first. You may do this manually or let AWS do this for you, in the latter case a new S3 bucket will be created with a generated name and the templates will be uploaded in it under the covers. It will be assumed further that a S3 bucket was created manually and templates were uploaded there beforehand.

Stats template is a bit different from others because it contains references to Lambda functions code that should be packaged and uploaded to S3 bucket and template itself have to be updated with the S3 bucket and code package location before it could be used. Fortunately this is a one step action, just run the following command to get code packaged and uploaded and template updated:

aws cloudformation package --template-file cloudformation/stats.yaml --s3-bucket <bucket_name> --s3-prefix <directory_path> --output-template-file cloudformation/stats-packaged.yaml

After running this command you will find a code package at <bucket_name>/<directory_path> on S3 and an updated template cloudformation/stats-packaged.yaml pointing to the uploaded code package, now you can use it to create resources as described below.

At first create the network stack:

  • Initiate CloudFormation stack creation
  • Pick a decent name for the stack, for example prebid-network-prod
  • Wait until all the resources are provisioned

After that create the service stack:

  • Initiate CloudFormation stack creation
  • Pick a decent name for the stack, for example pbjs-bundler-prod
  • Fill in desired input parameters, most notable and important of them are:
    • Api Image URL - specify ECR repository name and tag to deploy, for example <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-api:latest
    • Builder Image URL - specify ECR repository name and tag to deploy, for example <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/prebid/pbjs-bundle-service-builder:latest
    • Network Stack Name - specify the name of the network stack created previously, for example prebid-network-prod
    • Load Balancer Certificate ID - ID of the pre-uploaded (or pre-requested) SSL certificate from ACM (Amazon Certificate Manager)
    • Key Name - Name of an existing EC2 KeyPair to enable SSH access to the ECS instances
  • Wait until all the resources are provisioned

Finally create the stats stack:

  • Initiate CloudFormation stack creation
  • Pick a decent name for the stack, for example pbjs-bundler-stats-prod
  • Fill in desired input parameters, most notable and important of them are:
    • Service Stack Name - specify the name of the service stack created previously, for example pbjs-bundler-prod
    • Recipient Address List - comma-separated list of e-mail addresses where monthly report should be sent (must be verified in Amazon SES or belong to verified domain)
    • Source Address - e-mail address that should be specified in From: field of the monthly report messages (must be verified in Amazon SES or belong to verified domain)
  • Wait until all the resources are provisioned

Once all stacks are created application should be up and running, it could be accessed by ALB DNS name that is found on the Outputs tab of the service stack as ExternalUrl.

Set up sub-domain

AWS Route 53 allows to set up a sub-domain in prebid.org zone as an alias to the ALB. You'll have to create a new Record Set of A type, then select Alias and choose the corresponding ALB from the list resembling dualstack.<ALB_name>.<region>.elb.amazonaws.com.