Arun Stephens

Setting up SSL on an AWS Elastic Load Balancer

Here's how to get an SSL certificate (from DigiCert) and install it on your AWS ELB.

Step 1: Create the CSR

SSL is a form of PKI (public key infrastructure) encryption. It requires a key pair, which is usually generated by the user. Ideally the private key can be kept private, never moved from the computer on which it was generated. This isn't the case for ELBs though. The following steps need to be performed on a machine that has OpenSSL installed. Most web servers have it.

  1. Go to the DigiCert OpenSSL CSR Wizard.
  2. Fill out the fields. Everything is self-explanatory, but CN (common name) should be the site's domain name.
  3. Press Generate then copy the resulting text.
  4. In a terminal/command prompt, paste the generated command from the previous step, e.g.:
    $ openssl req -new -newkey rsa:2048 -nodes -out arun_nz.csr -keyout arun_nz.key -subj "/C=GB/ST=London/L=London/O=Arun Stephens/CN=arun.nz"
  5. Two files will be created. In this case, arun_nz.csr and arun_nz.key. Keep the .key file safe. Use the .csr file in the next step.

Step 2: Apply for the certificate

  1. Log into your DigiCert account
  2. Go to the order page.
  3. Choose the type of certificate (SSL Plus is a standard certificate, suitable for most uses) and duration of certificate validity.
  4. Enter the common name (CN) for the certificate. This will be the site's domain name.
  5. Check the I would like to provide my CSR and auto-fill names now box. Choose OTHER for server software, then paste in or upload the contents of the .csr file generated in Step 1, above.
  6. Press Continue.
  7. Verify/amend all the details, then press Continue.
  8. Enter your payment details.

Step 3: Wait for/assist in verification

DigiCert will now verify that you have control of the domain in order to issue the certificate. They do this by emailing the registered email addresses for the domain, as well as [email protected]<domain>. If you can't access those email addresses, you can contact DigiCert to manually verify your control by either adding a DNS record or adding a file to the web server, in both cases with your email address. They will then use that email address to continue with the verification process.

Once verified, your certificate will be emailed to you.

Step 4: Create an ELB and add the certificate to it

Once you have your certificate, you need to add it to a new ELB.

  1. Log into the AWS Console.
  2. Go to EC2. Make sure you are in the correct region.
  3. Click on Load Balancers in the side bar (or under Resources in the main part of the window.
  4. Click Create Load Balancer.
  5. Give it a name, make sure it is in the correct VPC (usually a public one for a web site).
  6. Keep the default HTTP listener, and also create a HTTPS (Secure HTTP) listener.
    These should both point to port 80, as SSL is not (and does not need to be) set up on the individual servers.
  7. If you have multiple subnets in different availability zones, Select the subnets that the load balancer should be in. For a public web site, choose the public subnets only.
  8. Click Assign Security Groups.
  9. Choose or create a security group that this load balancer should be part of. It should at least allow public access to ports 80 and 443.
  10. Click Configure Security Settings.
  11. Give the certificate a name. Names must be unique. When you renew the certificate once this one expires, you can't use this name again, so consider adding a date or year to the name to make it unique.
  12. Paste in the private key. This is the .key file you created in step 1, above.
  13. Paste in the public key certificate. This is the <domain>.crt file from the zip that DigiCert emailed you.
  14. Paste in the certificate chain. This is the DigiCertCA.crt file from the zip that DigiCert emailed you.
  15. Click Configure Health Check.
  16. Choose your health check settings. The ELB will check the web servers periodically using these settings. By default it will check for a particular URL. The default is /index.html. Make sure the file exists on the server(s).
  17. Click Add EC2 Instances.
  18. Choose the web server(s) that should be attached to the load balancer.
  19. Click Add Tags, then add any tags to the load balancer.
  20. Click Review and Create.
  21. Review everything, then click Create.

The load balancer is now created.

If you're not using Amazon Route 53 for DNS, you will need to create a CNAME record to the load balancer's domain name, which is available as the DNS Name in the console. It ends with elb.amazonaws.com.