-
-
Save rhzs/335f73c0636bf285034d5062776c44b2 to your computer and use it in GitHub Desktop.
Cloudformation template for Convey Test/Benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Description: Convey Test/Benchmark Environment | |
Parameters: | |
AmiId: | |
Type: String | |
Default: 'ami-03d5c68bab01f3496' | |
InstanceKeyPair: | |
Type: AWS::EC2::KeyPair::KeyName | |
Default: 'bparli' | |
InstanceSecurityGroup: | |
Type: AWS::EC2::SecurityGroup::Id | |
Default: 'sg-b58062da' | |
InstanceSubnet: | |
Type: AWS::EC2::Subnet::Id | |
Default: 'subnet-c355cbab' | |
InstanceVolumeSize: | |
Type: Number | |
Default: 8 | |
Resources: | |
Client: | |
Type: AWS::EC2::Instance | |
Properties: | |
InstanceType: 'c5.large' | |
Tags: | |
- Key: 'Name' | |
Value: 'wrk-client' | |
- Key: 'Role' | |
Value: 'client' # Used by cloud-init script | |
LaunchTemplate: | |
LaunchTemplateId: !Ref 'LaunchTemplate' | |
Version: !GetAtt 'LaunchTemplate.LatestVersionNumber' | |
Loadbalancer: | |
Type: AWS::EC2::Instance | |
Properties: | |
InstanceType: 'c5.xlarge' | |
Tags: | |
- Key: 'Name' | |
Value: 'loadbalancer' | |
- Key: 'Role' | |
Value: 'loadbalancer' # Used by cloud-init script | |
LaunchTemplate: | |
LaunchTemplateId: !Ref 'LaunchTemplate' | |
Version: !GetAtt 'LaunchTemplate.LatestVersionNumber' | |
Webserver1: | |
Type: AWS::EC2::Instance | |
Properties: | |
InstanceType: 'c5.large' | |
Tags: | |
- Key: 'Name' | |
Value: 'webserver1' | |
- Key: 'Role' # Used by cloud-init script | |
Value: 'webserver' | |
LaunchTemplate: | |
LaunchTemplateId: !Ref 'LaunchTemplate' | |
Version: !GetAtt 'LaunchTemplate.LatestVersionNumber' | |
Webserver2: | |
Type: AWS::EC2::Instance | |
Properties: | |
InstanceType: 'c5.large' | |
Tags: | |
- Key: 'Name' | |
Value: 'webserver2' | |
- Key: 'Role' # Used by cloud-init script | |
Value: 'webserver' | |
LaunchTemplate: | |
LaunchTemplateId: !Ref 'LaunchTemplate' | |
Version: !GetAtt 'LaunchTemplate.LatestVersionNumber' | |
ClusterPlacementGroup: | |
Type: AWS::EC2::PlacementGroup | |
Properties: | |
Strategy: cluster | |
# Allows 'aws ec2 describe-tags' to be called from the cloud-init script so it can differentiate client from server | |
Ec2Role: | |
Type: AWS::IAM::Role | |
Properties: | |
Path: / | |
Policies: | |
- PolicyName: 'AllowInstanceLogs' | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: [ 'ec2:DescribeTags' ] | |
Resource: '*' | |
AssumeRolePolicyDocument: | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: ['ec2.amazonaws.com'] | |
Action: ['sts:AssumeRole'] | |
Ec2InstanceProfile: | |
Type: AWS::IAM::InstanceProfile | |
Properties: | |
Path: / | |
Roles: [!Ref 'Ec2Role'] | |
LaunchTemplate: | |
Type: AWS::EC2::LaunchTemplate | |
Properties: | |
LaunchTemplateName: !Ref 'AWS::StackName' | |
LaunchTemplateData: | |
ImageId: !Ref 'AmiId' | |
KeyName: !Ref 'InstanceKeyPair' | |
IamInstanceProfile: | |
Arn: !GetAtt 'Ec2InstanceProfile.Arn' | |
Placement: | |
GroupName: !Ref 'ClusterPlacementGroup' | |
NetworkInterfaces: | |
- DeviceIndex: 0 | |
Ipv6AddressCount: 0 # Ensure that we don't get assigned any IPv6 addresses, even if it is the default for the subnet | |
SubnetId: !Ref 'InstanceSubnet' | |
Groups: | |
- !Ref 'InstanceSecurityGroup' | |
BlockDeviceMappings: | |
- DeviceName: '/dev/xvda' | |
Ebs: | |
VolumeSize: !Ref 'InstanceVolumeSize' | |
VolumeType: 'gp3' | |
UserData: | |
Fn::Base64: !Sub | | |
Content-Type: multipart/mixed; boundary="==BOUNDARY==" | |
MIME-Version: 1.0 | |
--==BOUNDARY== | |
Content-Type: text/cloud-config; charset="us-ascii" | |
Content-Disposition: attachment; filename="cloud-config.txt" | |
packages: | |
- net-tools | |
- git | |
- gcc | |
- make | |
- unzip | |
--==BOUNDARY== | |
Content-Type: text/x-shellscript; charset="us-ascii" | |
Content-Disposition: attachment; filename="user-data-script.txt" | |
#!/bin/bash | |
apt-get update | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip awscliv2.zip | |
sudo ./aws/install | |
# get role for installing packages | |
export INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
echo INSTANCE_ID = ${!INSTANCE_ID} | |
export INSTANCE_ROLE=$(aws ec2 describe-tags --region us-west-2 --filters "Name=resource-id,Values=${!INSTANCE_ID}" "Name=key,Values=Role" --output text | cut -f5) | |
echo INSTANCE_ROLE = ${!INSTANCE_ROLE} | |
if [ "${!INSTANCE_ROLE}" == "client" ]; then git clone https://github.com/wg/wrk.git /home/ubuntu/wrk && cd /home/ubuntu/wrk && make; fi | |
if [ "${!INSTANCE_ROLE}" == "webserver" ]; then apt install -y nginx; fi | |
if [ "${!INSTANCE_ROLE}" == "loadbalancer" ]; then apt install -y linux-headers-$(uname -r) clang-11 libelf-dev pkg-config nginx haproxy && git clone --branch feature/xdp https://github.com/bparli/convey.git /home/ubuntu/convey; fi | |
--==BOUNDARY==-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment