pub const SETUP_TEMPLATE: &str = r##"{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template EC2InstanceWithSecurityGroupSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example creates an EC2 security group for the instance to give you SSH access. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters" : {
"PublicKey": {
"Description" : "Public key material of pair for SSH access to the instance",
"Type": "String"
},
"InstanceName": {
"Description": "Name of the ec2 instance",
"Type": "String"
},
"Port": {
"Description": "Port to be opened in the security policy for TCP requests",
"Type": "Number",
"MinValue": 0,
"MaxValue": 65536
},
"InstanceType" : {
"Description" : "Type of the ec2 instance",
"Type" : "String",
"ConstraintDescription" : "Must be a virtualized Nitro-based instance type with at least two vCPUs, except t3, t3a, t4g, a1, c6g, c6gd, m6g, m6gd, r6g, and r6gd."
},
"SSHLocation" : {
"Description" : "The IP address range that can be used to SSH to the EC2 instances",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
"ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
},
"LatestAmiId": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
}
},
"Resources" : {
"ImportedKeyPair": {
"Type": "AWS::EC2::KeyPair",
"Properties": {
"KeyName": { "Ref": "InstanceName" },
"PublicKeyMaterial": { "Ref": "PublicKey"}
}
},
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init": {
"configSets": {
"Install": [
"Install"
]
},
"Install": {
"packages": {
"yum": {
"docker": [],
"aws-nitro-enclaves-cli": []
}
},
"services": {
"sysvinit": {
"docker": {
"enabled": "true",
"ensureRunning": "true"
}
}
},
"commands": {
"docker_for_ec2_user": {
"command": "usermod -aG docker ec2-user"
},
"nitro_cli_for_ec2_user": {
"command": "usermod -aG ne ec2-user"
}
}
}
}
},
"Properties" : {
"InstanceType" : { "Ref" : "InstanceType" },
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"KeyName" : { "Ref" : "ImportedKeyPair" },
"ImageId" : { "Ref" : "LatestAmiId" },
"EnclaveOptions": {
"Enabled": true
},
"Tags" : [
{"Key" : "Name", "Value" : { "Ref": "InstanceName"}}
],
"UserData": {
"Fn::Base64":{
"Fn::Join":[
"",
[
"#!/bin/bash -xe\n",
"yum install -y aws-cfn-bootstrap\n",
"amazon-linux-extras enable aws-nitro-enclaves-cli\n",
"# Install the files and packages from the metadata\n",
"/opt/aws/bin/cfn-init -v ",
" --stack ",
{ "Ref":"AWS::StackName" },
" --resource EC2Instance ",
" --configsets Install ",
" --region ",
{ "Ref":"AWS::Region" },
"\n",
"systemctl start nitro-enclaves-allocator.service && systemctl enable nitro-enclaves-allocator.service\n",
"systemctl start docker && systemctl enable docker\n",
"docker pull alpine/socat:latest\n",
"docker run -d -p",
{ "Ref" : "Port" },
":",
{ "Ref" : "Port" },
" --name socat alpine/socat tcp-listen:",
{ "Ref" : "Port" },
",fork,keepalive,reuseaddr vsock-connect:16:5000,keepalive\n"
]
]
}
}
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via port 22",
"SecurityGroupIngress" : [
{
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : { "Ref" : "SSHLocation"}
},
{
"IpProtocol" : "tcp",
"FromPort" : { "Ref" : "Port" },
"ToPort" : { "Ref" : "Port" },
"CidrIp" : "0.0.0.0/0"
}
]
}
}
},
"Outputs" : {
"InstanceId" : {
"Description" : "InstanceId of the newly created EC2 instance",
"Value" : { "Ref" : "EC2Instance" }
},
"AZ" : {
"Description" : "Availability Zone of the newly created EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "AvailabilityZone" ] }
},
"PublicDNS" : {
"Description" : "Public DNSName of the newly created EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PublicDnsName" ] }
},
"PublicIP" : {
"Description" : "Public IP address of the newly created EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PublicIp" ] }
}
}
}
"##;