Hey all! :wave: I’m trying to launch an EC2 insta...
# aws
m
Hey all! 👋 I’m trying to launch an EC2 instance that looks like:
Copy code
const server = new aws.ec2.Instance('xyz-staging-server-instance', {
  instanceType: 't2.micro',
  vpcSecurityGroupIds: [securityGroup.id], // reference the security group resource above
  ami: ami.id,
})
And I get the following error:
awsec2Instance (xyz-staging-server-instance):
error: 1 error occurred:
* Error launching source instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
I found this issue, which says specifying a subnet ID should help, but I can’t seem to work out how specifying the
subnetId
property should work 🤔 Has anyone seen/dealt with this before?
g
I've not seen that error before, but setting a
subnetID
is straightforward. If you have an existing Subnet you want to use can just set it as
subnetid: 'subnet-abc123'
. Otherwise you can create a VPC, Subnet, etc. and then pass the
subnetId
value in the same way.
m
Hey @gentle-diamond-70147 thank you for the quick reply 😄 So I have created a VPC:
Copy code
const stagingVpc = new awsx.ec2.Vpc(
  'xyz-staging',
  {
    numberOfNatGateways: 2,
    numberOfAvailabilityZones: 2,
    subnets: [
      { type: 'public', name: '1' },
      { type: 'public', name: '2' },
      { type: 'private', name: '1' },
      { type: 'private', name: '2' },
    ],
  },
  {}
)
And have a variable:
const stagingVpcPublicSubnetIds = stagingVpc.publicSubnetIds
I may be a bit rusty here, but I’m having difficulty taking one of those IDs into my EC2 instance, if I try: Do you know if there’s an easy way to grab the ID of one of those subnets as a string?
g
Ah, yea. It's not quite as straightforward as I mentioned when using awsx, but here's an example:
subnetId: pulumi.output(stagingVpc.publicSubnetIds).apply(it => it[0]),
🥇 1
m
Thank you @gentle-diamond-70147 that solved the issue! 🙇
👍 1