src/nat_instance.js
function buildNatInstance(imageId, zones = [], { name = 'NatInstance' } = {}) {
  if (!imageId) {
    return {};
  }
  if (!Array.isArray(zones) || zones.length < 1) {
    return {};
  }

  return {
    [name]: {
      Type: 'AWS::EC2::Instance',
      DependsOn: 'InternetGatewayAttachment',
      Properties: {
        AvailabilityZone: {
          'Fn::Select': ['0', zones],
        },
        BlockDeviceMappings: [
          {
            DeviceName: '/dev/xvda',
            Ebs: {
              VolumeSize: 10,
              VolumeType: 'gp2',
              DeleteOnTermination: true,
            },
          },
        ],
        ImageId: imageId, // amzn-ami-vpc-nat-hvm-2018.03.0.20181116-x86_64-ebs
        InstanceType: 't2.micro',
        Monitoring: false,
        NetworkInterfaces: [
          {
            AssociatePublicIpAddress: true,
            DeleteOnTermination: true,
            Description: 'eth0',
            DeviceIndex: '0',
            GroupSet: [
              {
                Ref: 'NatSecurityGroup',
              },
            ],
            SubnetId: {
              Ref: `${PUBLIC_SUBNET}Subnet1`,
            },
          },
        ],
        SourceDestCheck: false, // required for a NAT instance
        Tags: [
          {
            Key: 'Name',
            Value: {
              'Fn::Join': [
                '-',
                [
                  {
                    Ref: 'AWS::StackName',
                  },
                  'nat',
                ],
              ],
            },
          },
        ],
      },
    },
  };
}
function buildNatInstance(imageId, zones = [], { name = 'NatInstance' } = {}) {
  if (!imageId) {
    return {};
  }
  if (!Array.isArray(zones) || zones.length < 1) {
    return {};
  }

  return {
    [name]: {
      Type: 'AWS::EC2::Instance',
      DependsOn: 'InternetGatewayAttachment',
      Properties: {
        AvailabilityZone: {
          'Fn::Select': ['0', zones],
        },
        BlockDeviceMappings: [
          {
            DeviceName: '/dev/xvda',
            Ebs: {
              VolumeSize: 10,
              VolumeType: 'gp2',
              DeleteOnTermination: true,
            },
          },
        ],
        ImageId: imageId, // amzn-ami-vpc-nat-hvm-2018.03.0.20181116-x86_64-ebs
        InstanceType: 't2.micro',
        Monitoring: false,
        NetworkInterfaces: [
          {
            AssociatePublicIpAddress: true,
            DeleteOnTermination: true,
            Description: 'eth0',
            DeviceIndex: '0',
            GroupSet: [
              {
                Ref: 'NatSecurityGroup',
              },
            ],
            SubnetId: {
              Ref: `${PUBLIC_SUBNET}Subnet1`,
            },
          },
        ],
        SourceDestCheck: false, // required for a NAT instance
        Tags: [
          {
            Key: 'Name',
            Value: {
              'Fn::Join': [
                '-',
                [
                  {
                    Ref: 'AWS::StackName',
                  },
                  'nat',
                ],
              ],
            },
          },
        ],
      },
    },
  };
}
function buildNatInstance ( imageId , zones = [ ] , { name = 'NatInstance' } = { } ) { if ( ! imageId ) { return { } ; } if ( ! Array . isArray ( zones ) || zones . length < 1 ) { return { } ; } return { [ name ] : { Type : 'AWS::EC2::Instance' , DependsOn : 'InternetGatewayAttachment' , Properties : { AvailabilityZone : { 'Fn::Select' : [ '0' , zones ] , } , BlockDeviceMappings : [ { DeviceName : '/dev/xvda' , Ebs : { VolumeSize : 10 , VolumeType : 'gp2' , DeleteOnTermination : true , } , } , ] , ImageId : imageId , // amzn-ami-vpc-nat-hvm-2018.03.0.20181116-x86_64-ebs InstanceType : 't2.micro' , Monitoring : false , NetworkInterfaces : [ { AssociatePublicIpAddress : true , DeleteOnTermination : true , Description : 'eth0' , DeviceIndex : '0' , GroupSet : [ { Ref : 'NatSecurityGroup' , } , ] , SubnetId : { Ref : ` ${ PUBLIC_SUBNET } ` , } , } , ] , SourceDestCheck : false , // required for a NAT instance Tags : [ { Key : 'Name' , Value : { 'Fn::Join' : [ '-' , [ { Ref : 'AWS::StackName' , } , 'nat' , ] , ] , } , } , ] , } , } , } ; }
Build the NAT instance

@param {Object} imageId AMI image ID
@param {Array} zones Array of availability zones
@param {Object} params
@return {Object}
Build the NAT instance