AWSTemplateFormatVersion: 2010-09-09 Description: "Singularity (HPC Container) on CfnCluster" Mappings: SubnetConfig: VPC: CIDR: 10.0.0.0/16 Prepost: CIDR: 10.0.0.0/24 Cluster: CIDR: 10.0.1.0/24 RegionMap: # Ubuntu 16.04 LTS, hvm:ebs-ssd # See Also: https://cloud-images.ubuntu.com/locator/ec2/ us-east-1: "ubuntuimgid": "ami-66506c1c" us-east-2: "ubuntuimgid": "ami-965e6bf3" us-west-1: "ubuntuimgid": "ami-07585467" us-west-2: "ubuntuimgid": "ami-79873901" ca-central-1: "ubuntuimgid": "ami-173db873" eu-west-1: "ubuntuimgid": "ami-1b791862" eu-west-2: "ubuntuimgid": "ami-941e04f0" eu-west-3: "ubuntuimgid": "ami-c1cf79bc" eu-central-1: "ubuntuimgid": "ami-5055cd3f" ap-southeast-1: "ubuntuimgid": "ami-b7f388cb" ap-southeast-2: "ubuntuimgid": "ami-33ab5251" ap-northeast-1: "ubuntuimgid": "ami-48630c2e" ap-northeast-2: "ubuntuimgid": "ami-ab77d4c5" ap-south-1: "ubuntuimgid": "ami-84e3b2eb" sa-east-1: "ubuntuimgid": "ami-bb9bd7d7" Parameters: KeyPairName: Type: AWS::EC2::KeyPair::KeyName Description: Choose your keypair InstanceTypeParameter: Type: String Default: t2.micro AllowedValues: - t2.micro - t2.medium - m4.large Description: Enter t2.micro, t2.medium, or m4.large. Default is t2.micro. SourceIp: Type: String Default: 0.0.0.0/0 Description: Enter your global IP address. SSH access from the IP is allowed. FYI http://checkip.amazonaws.com/ Resources: VPC: Type: AWS::EC2::VPC Properties: EnableDnsSupport: true EnableDnsHostnames: true CidrBlock: Fn::FindInMap: - SubnetConfig - VPC - CIDR Tags: - Key: Name Value: "Singularity on CfnCluster" - Key: Application Value: !Ref AWS::StackName InternetGateway: Type: AWS::EC2::InternetGateway DependsOn: VPC Properties: Tags: - Key: Application Value: !Ref AWS::StackName AttachGateway: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !Ref VPC InternetGatewayId: !Ref InternetGateway PrepostSubnet: Type: AWS::EC2::Subnet DependsOn: AttachGateway Properties: VpcId: !Ref VPC MapPublicIpOnLaunch: true AvailabilityZone: Fn::Select: - 0 - Fn::GetAZs: "" CidrBlock: Fn::FindInMap: - SubnetConfig - Prepost - CIDR Tags: - Key: Name Value: "PrePost Subnet" - Key: Application Value: !Ref AWS::StackName ClusterSubnet: Type: AWS::EC2::Subnet DependsOn: AttachGateway Properties: VpcId: !Ref VPC MapPublicIpOnLaunch: true AvailabilityZone: Fn::Select: - 0 - Fn::GetAZs: "" CidrBlock: Fn::FindInMap: - SubnetConfig - Cluster - CIDR Tags: - Key: Name Value: "Cluster Subnet" - Key: Application Value: !Ref AWS::StackName PublicRouteTable: Type: AWS::EC2::RouteTable DependsOn: - VPC - AttachGateway Properties: VpcId: !Ref VPC Tags: - Key: Name Value: Public - Key: Application Value: !Ref AWS::StackName PublicRoute: Type: AWS::EC2::Route DependsOn: AttachGateway Properties: RouteTableId: !Ref PublicRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway PrepostSubnetRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation DependsOn: AttachGateway Properties: SubnetId: !Ref PrepostSubnet RouteTableId: !Ref PublicRouteTable ClusterSubnetRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation DependsOn: AttachGateway Properties: SubnetId: !Ref ClusterSubnet RouteTableId: !Ref PublicRouteTable SecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: SecurityGroup for PrePost instance (allow ssh) VpcId: !Ref VPC SecurityGroupIngress: - IpProtocol: tcp FromPort: '22' ToPort: '22' CidrIp: !Ref SourceIp Tags: - Key: Name Value: PrepostInstanceSecGrp - Key: Application Value: !Ref AWS::StackName IamUser: Type: "AWS::IAM::User" Properties: ManagedPolicyArns: - arn:aws:iam::aws:policy/AdministratorAccess AccessKey: Type: AWS::IAM::AccessKey Properties: UserName: !Ref IamUser PrepostEC2: Type: AWS::EC2::Instance Properties: ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", ubuntuimgid] InstanceType: !Ref InstanceTypeParameter KeyName: !Ref KeyPairName SecurityGroupIds: - Ref: "SecurityGroup" SubnetId: !Ref PrepostSubnet BlockDeviceMappings: - DeviceName: "/dev/sda1" Ebs: VolumeType: "gp2" VolumeSize: "45" DeleteOnTermination: "true" Tags: - Key: Name Value: PrePost UserData: Fn::Base64: !Sub | #!/bin/bash -x exec > >(tee /var/log/user-data.log || logger -t user-data -s 2> /dev/console) 2>&1 cd /home/ubuntu apt-get -y update wget https://raw.githubusercontent.com/TakahisaShiratori/singularity-on-cfncluster/master/configure_cfncluster.sh chmod 777 ./configure_cfncluster.sh sudo -u ubuntu ./configure_cfncluster.sh rm configure_cfncluster.sh Outputs: PrePostIp: Description: Global IP adress of PrePost EC2 (Ubuntu) Value: !GetAtt PrepostEC2.PublicIp Region: Value: !Ref AWS::Region AccessKey: Description: Access Key used by CfnCluster Value: !Ref AccessKey SecretAccessKey: Description: Secret Access Key used by CfnCluster Value: !GetAtt AccessKey.SecretAccessKey KeyPairName: Value: !Ref KeyPairName VpcId: Value: !Ref VPC MasterSubnetId: Value: !Ref ClusterSubnet SourceIp: Description: Source IP for SSH Access Value: !Ref SourceIp