Instructor notes

SKIP THIS LAB IF YOU ARE NOT THE WORKSHOP INSTRUCTOR.

Use the CloudFormation template below to create 4 EC2 instances in different regions (Ohio, Singapore, Paris and Sao Paulo) that will be used by the workshop participants to test their accelerator settings.

CloudFormation template

---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS Global Accelerator Workshop - This CloudFormation template creates an EC2 instance with HTTPD and PHP installed.'
Parameters:
  InstanceType:
    Description: WebServer EC2 instance type
    Type: String
    Default: t2.micro
    AllowedValues:
    - t2.micro
    - t3.micro
    - t3.small
    - t3.medium
    ConstraintDescription: must be a valid EC2 instance type.
  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
    Type: AWS::EC2::KeyPair::KeyName
    MinLength: '1'
    MaxLength: '255'
    AllowedPattern: "[\\x20-\\x7E]*"
    ConstraintDescription: can contain only ASCII characters.
Mappings:
  RegionMap:
    'eu-north-1':
      AMI: 'ami-0c947472aff72870d'
    'ap-south-1':
      AMI: 'ami-040c7ad0a93be494e'
    'eu-west-3':
      AMI: 'ami-05a51ff00c1d77571'
    'eu-west-2':
      AMI: 'ami-00e8b55a2e841be44'
    'eu-west-1':
      AMI: 'ami-040ba9174949f6de4'
    'ap-northeast-2':
      AMI: 'ami-02b3330196502d247'
    'me-south-1':
      AMI: 'ami-0207e6a966ca96048'
    'ap-northeast-1':
      AMI: 'ami-0064e711cbc7a825e'
    'sa-east-1':
      AMI: 'ami-053f8b6627112b46e'
    'ca-central-1':
      AMI: 'ami-007dbcbce3118978b'
    'ap-east-1':
      AMI: 'ami-ff4d378e'
    'ap-southeast-1':
      AMI: 'ami-00942d7cd4f3ca5c0'
    'ap-southeast-2':
      AMI: 'ami-08a74056dfd30c986'
    'eu-central-1':
      AMI: 'ami-0f3a43fbf2d3899f7'
    'us-east-1':
      AMI: 'ami-00dc79254d0461090'
    'us-east-2':
      AMI: 'ami-00bf61217e296b409'
    'us-west-1':
      AMI: 'ami-024c80694b5b3e51a'
    'us-west-2':
      AMI: 'ami-0a85857bfc5345c38'
Resources:
  WebServerInstance:
    Type: AWS::EC2::Instance
    Properties:
      KeyName: !Ref KeyName
      ImageId: !FindInMap [RegionMap, !Ref 'AWS::Region', AMI]
      SecurityGroups: [!Ref InstanceSecurityGroup]
      InstanceType: !Ref InstanceType
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          yum update -y
          yum install -y httpd php
          systemctl start httpd
          systemctl enable httpd
          mkdir /var/www/html/outputs
          wget -P /var/www/html/ https://jtouzi.s3.amazonaws.com/GlobalAccelerator/ga.php
          usermod -a -G apache ec2-user
          chown -R ec2-user:apache /var/www
          chmod 2775 /var/www
          find /var/www -type d -exec chmod 2775 {} \;
          find /var/www -type f -exec chmod 0664 {} \;
  InstanceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Enable SSH access and HTTP access on the configured port
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '22'
        ToPort: '22'
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: '80'
        ToPort: '80'
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: '443'
        ToPort: '443'
        CidrIp: 0.0.0.0/0
Outputs:
  URL:
    Description: URL of the website
    Value: !Join ['', ['http://', !GetAtt [WebServerInstance, PublicDnsName]]]
  PublicIp:
    Description: IP of the EC2 instance
    Value: !GetAtt [WebServerInstance, PublicIp]

Create stacks in the regions with the CLI commands below

Copy the above CloudFormation template and create a file named ec2.yaml. Make sure you have a Key Pair in each of the four regions (Ohio, Singapore, Paris and Sao Paulo), for more information see EC2 Key Pairs in the documentation.

$ aws cloudformation create-stack --stack-name AGAEC2 --template-body file://ec2.yaml --parameters ParameterKey=KeyName,ParameterValue=YourSaoPauloKey --region sa-east-1

$ aws cloudformation create-stack --stack-name AGAEC2 --template-body file://ec2.yaml --parameters ParameterKey=KeyName,ParameterValue=YourParisKey --region eu-west-3

$ aws cloudformation create-stack --stack-name AGAEC2 --template-body file://ec2.yaml --parameters ParameterKey=KeyName,ParameterValue=YourSingaporeKey --region ap-southeast-1

$ aws cloudformation create-stack --stack-name AGAEC2 --template-body file://ec2.yaml --parameters ParameterKey=InstanceType,ParameterValue=t3.medium ParameterKey=KeyName,ParameterValue=YourOhioKey --region us-east-2

Get the IP addresses of the EC2 instances

$ aws cloudformation describe-stacks --stack-name AGAEC2 --query "Stacks[0].Outputs[?OutputKey=='PublicIp'].OutputValue" --output text --region us-east-2

$ aws cloudformation describe-stacks --stack-name AGAEC2 --query "Stacks[0].Outputs[?OutputKey=='PublicIp'].OutputValue" --output text --region ap-southeast-1

$ aws cloudformation describe-stacks --stack-name AGAEC2 --query "Stacks[0].Outputs[?OutputKey=='PublicIp'].OutputValue" --output text --region eu-west-3

$ aws cloudformation describe-stacks --stack-name AGAEC2 --query "Stacks[0].Outputs[?OutputKey=='PublicIp'].OutputValue" --output text --region sa-east-1

Create an index.php file with the following content

<?php
$n = $_GET["n"];
$url = $_GET["url"];

$correctURL = 1;

if (substr($url, -24, 24) != "awsglobalaccelerator.com" && substr($url, -17, 17) != "elb.amazonaws.com") $correctURL = 0;

//IP addresses or DNS of the EC2 instance created
$EC2_SaoPaulo = "";
$EC2_Paris = "";
$EC2_Singapore = "";
$EC2_Ohio = "";

?>
<!DOCTYPE html>
<html>

   <head>
      <title>Test - AWS Global Accelerator</title>
   </head>

<body style="font-size:17px;font-family:'Amazon Ember'">

<table align="center" width="1050" style="margin-top:30px;">
  <tr style="font-size:20px">
    <td align="center" colspan="2" style="color:red;padding:50px">
      Note: This web page is NOT testing performance, it's just to show how AWS Global Accelerator routes requests based on users locations and the Accelerator settings (traffic dials, endpoint weights, failover, etc.). If you want to test performance use real clients, or the Speed Comparison Tool (<a href="https://speedtest.globalaccelerator.aws/#/" target="_blank">https://speedtest.globalaccelerator.aws/#/</a>).
    </td>
  </tr>
  <tr style="font-size:20px">
    <td align="center" colspan="2">
      <form action="" method="get" style="font-size:13px;font-family:'Amazon Ember'">
        Endpoint: <input type="text" name="url" size="40" value="<?php echo $url;?>">&nbsp;&nbsp;&nbsp;
        <select name="n">
        <option value="10">10 requests</option>
        <option value="20">20 requests</option>
        <option value="50">50 requests</option>
        <option value="100">100 requests</option>
      </select>
        <input type="submit">
      </form>
<?php if ($n != "" && $url !="") echo "<p>Endpoint: " .$url. ", ".$n." requests per client</p>"; ?>
    </td>
  </tr>

  <?php
  if ($correctURL != 1) echo "<tr><td align=\"center\" colspan=\"2\">Please enter a valid Global Accelerator (x.awsglobalaccelerator.com) or ALB (x.elb.amazonaws.com) endpoint.</td></tr>";
  else {
  ?>

  <tr style="font-size:25px">
    <td align="left">From Ohio</td>
    <td align="left">From Singapore</td>
  </tr>
  <tr>
    <td align="left" width="50%">
      <iframe src = "http://<?php echo $EC2_Ohio."/ga.php?n=".$n."&url=".$url;?>" style="border:0px;overflow:hidden;height:100px;width:500px;font-family:'Amazon Ember'">
         Sorry your browser does not support inline frames.
      </iframe>
    </td>
    <td align="left" width="50%">
      <iframe src = "http://<?php echo $EC2_Singapore."/ga.php?n=".$n."&url=".$url;?>" style="border:0px;overflow:hidden;height:100px;width:550px;font-family:'Amazon Ember'">
         Sorry your browser does not support inline frames.
      </iframe>
    </td>
  </tr>
  <tr style="font-size:25px">
    <td align="left">From Paris</td>
    <td align="left">From Sao Paulo</td>
  </tr>
  <tr style="font-size:25px;">
    <td align="left" width="50%">
      <iframe src = "http://<?php echo $EC2_Paris."/ga.php?n=".$n."&url=".$url;?>" style="border:0px;overflow:hidden;height:100px;width:500px;font-family:'Amazon Ember';">
         Sorry your browser does not support inline frames.
      </iframe>
    </td>
    <td align="left" width="50%">
      <iframe src = "http://<?php echo $EC2_SaoPaulo."/ga.php?n=".$n."&url=".$url;?>" style="border:0px;overflow:hidden;height:100px;width:500px;font-family:'Amazon Ember'">
             Sorry your browser does not support inline frames.
          </iframe>
    </td>
  </tr>
  <?php
  }
  ?>
 </table>

   </body>

</html>

Update index.php you just created with the EC2 instance IPs or DNSs (e.g.)

$EC2_SaoPaulo = "18.231.143.234";
$EC2_Paris = "15.236.45.221";
$EC2_Singapore = "54.52.197.134";
$EC2_Ohio = "18.188.56.13";

Upload the index.php file in us-east-2 region

scp -i /path/to/Key/YourOhioKey.pem index.php ec2-user@OHIO_IP:/var/www/html/

Share the Ohio DNS to the participants so they can test their accelerator settings

$ aws cloudformation describe-stacks --stack-name AGAEC2 --query "Stacks[0].Outputs[?OutputKey=='URL'].OutputValue" --output text --region us-east-2

Clean up AT THE END of the workshop

$ aws cloudformation delete-stack --stack-name AGAEC2 --region us-east-2
$ aws cloudformation delete-stack --stack-name AGAEC2 --region sa-east-1
$ aws cloudformation delete-stack --stack-name AGAEC2 --region eu-west-3
$ aws cloudformation delete-stack --stack-name AGAEC2 --region ap-southeast-1