Hi! I'm trying to create a bastion host to connect...
# aws
Hi! I'm trying to create a bastion host to connect my private (subnet) RDS. I created a VPC with
and it throws an error at assigning public subnet ID from newly created VPC to a new EC2 instance. Please help me.
Copy code
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,
The publicSubnetIds array is automatically lifted. Don't use
subnetId: vpc.publicSubnetIds[0]
works fine.
I tried but it says
1. Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<Output<string>[]>'.
Property '0' does not exist on type 'Promise<Output<string>[]>'.
Ah, that's awsx for you. Promises instead of outputs. Is there an equivalent method / member that gives outputs?
If not, then you can wrap the value in an output. That'll allow Pulumi to lift the values correctly.
I think this should do it?
Copy code
subnetId: pulumi.output(vpc.publicSubnetIds)[0]
It works! Thanks, brother.