How to assign VPC's public subnet ID to the EC2 instance (bastion host)?

Viewed 35

I'm trying to create a bastion host to connect my private (subnet) RDS. I created a VPC with awsx and it throws an error at assigning public subnet ID from newly created VPC to a new EC2 instance.

const vpc = new awsx.ec2.Vpc("my-vpc");

// Create bastion host
const bastionHost = new awsc.ec2.Instance("bastion-host", {
  ami: ami.id,
  instanceType: awsc.ec2.InstanceTypes.T2_Micro,
  associatePublicIpAddress: true,

  // Reference the public subnet from the custom vpc above
  subnetId: vpc.publicSubnetIds.apply(x => x![0]), // ! Property apply does not exist on type ...

  vpcSecurityGroupIds: [ec2SecurityGroup.id],
  keyName: sshKey.keyName,
});

How do I assign VPC's public subnet ID to the EC2 instance (bastion host)? Please help me.

0 Answers
Related