/dns-and-lb-copilot-demo

A simple demo app with two services which share a load balancer, and DNS.

Primary LanguageHTML

DNS, HTTPS, Shared Load Balancers

In this little demo application we'll create a new application called copilot-demos which will use the 'myhappylittle.cloud'

Step 1:

In this example, we'll start by creating an application and associating my domain name myhappylittle.cloud to it. This domain name is registered with Route53 in my account - but will work as long as there's a correctly configured hosted zone with that name in your account.

copilot app init copilot-demos --domain myhappylittle.cloud

App Init

Step 2:

Now we'll set up our first front-end service. To do this, we'll run the copilot init command and select a Load Balanced Web Service as our service type. Copilot will extract the exposed port from the Dockerfile and forward traffic from the load balancer there.

In this example, I'll set up my test environment in another account by using the --profile account. You don't have to do this, but this goes to show that Copilot can delegate DNS across accounts.

copilot init --profile prod-acc

Init

Step 3:

Now let's set up our second front-end service. The process is the same. As with all Copilot commands, if you'd like to skip the wizard experience, you can pass in values as a flag.

Notice how this time, the setup is much faster. That's because the test environment already exists and doesn't need to be created. Instead, our second service will use the resources already provisioned in the test environment, including the Load Balancer.

copilot init --profile prod-acc

Init

Tadah

Now you can access

https://svc1.test.copilot-demos.myhappylittle.cloud/ https://svc2.test.copilot-demos.myhappylittle.cloud/

Which are two separate services, behind the same Application Load Balancer.

Copilot took care of the ACM Cert generation and validation, DNS Subdomain delegation across accounts and spinning up the services.

Svc1 Svc2

Setting up CI/CD

In this section, we'll set up a Continuous Delivery pipeline powered by AWS CodePipeline.

Step 1:

In this example, we'll set up a pipeline that deploys both svc1 and svc2. You can also set up a single pipeline per service. We'll start off by running pipeline init and walking through the wizard. We'll need a GitHub personal access token with repo and admin:repo_hook permissions.

copilot pipeline init

Step 2:

This will generate a pipeline.yml file in your copilot directory. Let's update that to trigger whenever we push to our release branch.

Editing Pipeline

Step 3:

Now, let's push this code to our release branch:

git add . && git commit -m "Adding Pipeline config" && git push origin mainline:release

And finally, deploy our pipeline:

copilot pipeline update

Pipeline Status

Now, every time we push to our release branch, svc1 and svc2 will be deployed.