pulumi-awsx: Help requested: awsx.ec2.Vpc.getDefault() causes `no matching VPC found` error

I was following this guide: https://www.pulumi.com/blog/get-started-with-docker-on-aws-fargate-using-pulumi/

and started to the the no matching VPC found error

I slimmed the code down to the following:

import * as awsx from '@pulumi/awsx';
import * as pulumi from '@pulumi/pulumi';

const vpc = awsx.ec2.Vpc.getDefault();

export const vpcId: pulumi.Output<string> = vpc.id;

And it still results in the following error:

Error: invocation of aws:ec2/getVpc:getVpc returned an error: invoking aws:ec2/getVpc:getVpc: no matching VPC found

Based on this article: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.FindDefaultVPC.html

It looks like I’m an EC2-Classic user and don’t have a default VPC.

Is there any workaround for this issue? Should I just create a new VPC and use that?

Would the following be the correct way to accomplish that?

import * as awsx from '@pulumi/awsx';
import * as pulumi from '@pulumi/pulumi';

const vpc = new awsx.ec2.Vpc('fargateTestVPC');

const cluster = new awsx.ecs.Cluster('cluster', {
  vpc,
});

const alb = new awsx.lb.ApplicationLoadBalancer('net-lb', {
  external: true,
  securityGroups: cluster.securityGroups,
  vpc,
});

const web = alb.createListener('web', {
  port: 80,
  external: true,
});

const img = awsx.ecs.Image.fromPath('app-img', './app');

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore: appService is declared by never read
const appService = new awsx.ecs.FargateService('app-svc', {
  cluster,
  taskDefinitionArgs: {
    container: {
      image: img,
      cpu: 128 /* ~10% */,
      memory: 50 /* MB */,
      portMappings: [web],
    },
  },
  desiredCount: 2,
});

export const vpcId: pulumi.Output<string> = vpc.id;
export const webUrl: pulumi.Output<string> = web.endpoint.hostname;

Final question: What’s the correct way to “import” and existing VPC? I tried the following:

const vpc = new awsx.ec2.Vpc('fargateTestVPC', {}, { import: 'vpc-40b38f25' });

But the plan said it was going to create a new one instead of import that vpc with the provided id

Thanks in advance

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Note that it would be nice for the awsx library to report a better error message in case the default VPC cannot be found - pointing users at either creating their own or using fromExistingIds.

@chaffees If you pass subnetIds or subnetMappings or subnets to the LB declaration, it will use those (and the related VPC) instead of looking for the default VPC.

https://www.pulumi.com/registry/packages/awsx/api-docs/lb/applicationloadbalancer/#subnetids_nodejs

I get the exact same error, even if I create and specify a new VPC. It only happens when trying out FargateService. I did something similar with an EKS cluster and it did not throw the error.