src/bastion.js
function buildBastionLaunchConfiguration(
  keyPairName,
  { name = 'BastionLaunchConfiguration' } = {},
) {
  return {
    [name]: {
      Type: 'AWS::AutoScaling::LaunchConfiguration',
      Properties: {
        AssociatePublicIpAddress: true,
        BlockDeviceMappings: [
          {
            DeviceName: '/dev/xvda',
            Ebs: {
              VolumeSize: 10,
              VolumeType: 'gp2',
              DeleteOnTermination: true,
            },
          },
        ],
        KeyName: keyPairName,
        ImageId: {
          Ref: 'LatestAmiId',
        },
        InstanceMonitoring: false,
        IamInstanceProfile: {
          Ref: 'BastionInstanceProfile',
        },
        InstanceType: 't2.micro',
        SecurityGroups: [
          {
            Ref: 'BastionSecurityGroup',
          },
        ],
        SpotPrice: '0.0116', // On-Demand price of t2.micro in us-east-1
        // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-helper-scripts-reference.html
        UserData: {
          'Fn::Base64': {
            'Fn::Join': [
              '',
              [
                '#!/bin/bash -xe\n',
                '/usr/bin/yum update -y\n',
                '/usr/bin/yum install -y aws-cfn-bootstrap\n',
                'EIP_ALLOCATION_ID=',
                { 'Fn::GetAtt': ['BastionEIP', 'AllocationId'] },
                '\n',
                'INSTANCE_ID=`/usr/bin/curl -sq http://169.254.169.254/latest/meta-data/instance-id`\n',
                // eslint-disable-next-line no-template-curly-in-string
                '/usr/bin/aws ec2 associate-address --instance-id ${INSTANCE_ID} --allocation-id ${EIP_ALLOCATION_ID} --region ',
                { Ref: 'AWS::Region' },
                '\n',
                '/opt/aws/bin/cfn-signal --exit-code 0 --stack ',
                { Ref: 'AWS::StackName' },
                ' --resource BastionAutoScalingGroup ',
                ' --region ',
                { Ref: 'AWS::Region' },
                '\n',
              ],
            ],
          },
        },
      },
    },
  };
}
function buildBastionLaunchConfiguration(
  keyPairName,
  { name = 'BastionLaunchConfiguration' } = {},
) {
  return {
    [name]: {
      Type: 'AWS::AutoScaling::LaunchConfiguration',
      Properties: {
        AssociatePublicIpAddress: true,
        BlockDeviceMappings: [
          {
            DeviceName: '/dev/xvda',
            Ebs: {
              VolumeSize: 10,
              VolumeType: 'gp2',
              DeleteOnTermination: true,
            },
          },
        ],
        KeyName: keyPairName,
        ImageId: {
          Ref: 'LatestAmiId',
        },
        InstanceMonitoring: false,
        IamInstanceProfile: {
          Ref: 'BastionInstanceProfile',
        },
        InstanceType: 't2.micro',
        SecurityGroups: [
          {
            Ref: 'BastionSecurityGroup',
          },
        ],
        SpotPrice: '0.0116', // On-Demand price of t2.micro in us-east-1
        // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-helper-scripts-reference.html
        UserData: {
          'Fn::Base64': {
            'Fn::Join': [
              '',
              [
                '#!/bin/bash -xe\n',
                '/usr/bin/yum update -y\n',
                '/usr/bin/yum install -y aws-cfn-bootstrap\n',
                'EIP_ALLOCATION_ID=',
                { 'Fn::GetAtt': ['BastionEIP', 'AllocationId'] },
                '\n',
                'INSTANCE_ID=`/usr/bin/curl -sq http://169.254.169.254/latest/meta-data/instance-id`\n',
                // eslint-disable-next-line no-template-curly-in-string
                '/usr/bin/aws ec2 associate-address --instance-id ${INSTANCE_ID} --allocation-id ${EIP_ALLOCATION_ID} --region ',
                { Ref: 'AWS::Region' },
                '\n',
                '/opt/aws/bin/cfn-signal --exit-code 0 --stack ',
                { Ref: 'AWS::StackName' },
                ' --resource BastionAutoScalingGroup ',
                ' --region ',
                { Ref: 'AWS::Region' },
                '\n',
              ],
            ],
          },
        },
      },
    },
  };
}
function buildBastionLaunchConfiguration ( keyPairName , { name = 'BastionLaunchConfiguration' } = { } , ) { return { [ name ] : { Type : 'AWS::AutoScaling::LaunchConfiguration' , Properties : { AssociatePublicIpAddress : true , BlockDeviceMappings : [ { DeviceName : '/dev/xvda' , Ebs : { VolumeSize : 10 , VolumeType : 'gp2' , DeleteOnTermination : true , } , } , ] , KeyName : keyPairName , ImageId : { Ref : 'LatestAmiId' , } , InstanceMonitoring : false , IamInstanceProfile : { Ref : 'BastionInstanceProfile' , } , InstanceType : 't2.micro' , SecurityGroups : [ { Ref : 'BastionSecurityGroup' , } , ] , SpotPrice : '0.0116' , // On-Demand price of t2.micro in us-east-1 // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-helper-scripts-reference.html UserData : { 'Fn::Base64' : { 'Fn::Join' : [ '' , [ '#!/bin/bash -xe\n' , '/usr/bin/yum update -y\n' , '/usr/bin/yum install -y aws-cfn-bootstrap\n' , 'EIP_ALLOCATION_ID=' , { 'Fn::GetAtt' : [ 'BastionEIP' , 'AllocationId' ] } , '\n' , 'INSTANCE_ID=`/usr/bin/curl -sq http://169.254.169.254/latest/meta-data/instance-id`\n' , // eslint-disable-next-line no-template-curly-in-string '/usr/bin/aws ec2 associate-address --instance-id ${INSTANCE_ID} --allocation-id ${EIP_ALLOCATION_ID} --region ' , { Ref : 'AWS::Region' } , '\n' , '/opt/aws/bin/cfn-signal --exit-code 0 --stack ' , { Ref : 'AWS::StackName' } , ' --resource BastionAutoScalingGroup ' , ' --region ' , { Ref : 'AWS::Region' } , '\n' , ] , ] , } , } , } , } , } ; }
Build the auto-scaling group launch configuration for the bastion host

@param {String} keyPairName Existing key pair name
@param {Object} params
@return {Object}
Build the auto - scaling group launch configuration for the bastion host