This template deploys elastic beanstalk into a new VPC, specifically amazons VPC architecture quick start VPC 100. The instances are deployed into private subnets and the Application Load Balancer (ALB) into public subnets. A route is created into the service with the format <service_name>.<domain_name>.

The template can utilise all of the standard beanstalk backends, ruby, python, node, docker, ecs, tomcat, go, php, dotnet. AWS Certificate manager backed HTTPS can be enabled but this will require an existing MX record in the hosted zone. 101

There are also options to add Elasticache and some other options. In the case of AWS components such as Elasticache, some standard environment variables are also created such as REDIS_URL.

Elastic Beanstalk into a new VPC

Create a standard routed ruby-based website

aws --region eu-west-1 cloudformation create-stack \
  --stack-name mysite-yeefpib8 \
  --template-body file://beanstalk-with-vpc.template.template \
  --parameters \ 
    ParameterKey=HostedZone,ParameterValue=example.com \
    ParameterKey=ServiceName,ParameterValue=mynewsite \
    ParameterKey=SolutionType,ParameterValue=ruby \
    ParameterKey=KeyPairName,ParameterValue=default-keypair

Parameter options available.

HostedZone:The domain name
    Type: String
    Default: integration.dsd.io
  ServiceName:
    Description: The service name
    Type: String
  SolutionType:
    Default: ruby
    Type: String
    AllowedValues: [ruby, python, node, docker, ecs, tomcat, go, php, dotnet]
  KeyPairName:
    Type: AWS::EC2::KeyPair::KeyName
    Default: default
  EnableHTTPS:
    Default: false
    Type: String
    AllowedValues: [true, false]
  EnableElasticache:
    Default: false
    Type: String
    AllowedValues: [true, false]
  EnableRollingUpdates:
    Default: false
    Type: String
    AllowedValues: [true, false]
  ValidationDomain:
    Description: The validation domain name
    Type: String
    Default: dsd.io
curl mynewsite.example.com

Elastic Beanstalk into an existing VPC

This template is the same as the new VPC version, but requires the passing of VPCId, and at least 2 private and public subnets.

aws --region eu-west-1 cloudformation create-stack \
  --stack-name mysite-yeefpib8 \
  --template-body file://beanstalk-with-vpc.template.template \
  --parameters \ 
    ParameterKey=HostedZone,ParameterValue=example.com \
    ParameterKey=ServiceName,ParameterValue=mynewsite \
    ParameterKey=SolutionType,ParameterValue=ruby \
    ParameterKey=KeyPairName,ParameterValue=default-keypair \
    ParameterKey=VPCId,ParameterValue=default-keypair \
    ParameterKey=PublicSubnetIds,ParameterValue=subnetid-AAA, subnetid-BBB \
    ParameterKey=PrivateSubnetIds,ParameterValue=subnetid-XXX, subnetid-YYY

Additional required parameters to configure the VPC

  VPCId:
    Type: AWS::EC2::VPC::Id
    Description: The VPC to deploy into
  PublicSubnetIds:
    Type: List<AWS::EC2::Subnet::Id>
    Description: At least two public subnets ids in the VPC to deploy the ALB
  PrivateSubnetIds:
    Type: List<AWS::EC2::Subnet::Id>
    Description: At least two private subnet  ids in the VPC to deploy the ALB