hello! I'm trying out pulumi and im trying to chan...
# getting-started
a
hello! I'm trying out pulumi and im trying to change one of the fargate awsx tutorials to use ec2. but im getting stumped 😢
Copy code
import * as awsx from "@pulumi/awsx";

const lb = new awsx.lb.NetworkListener("loadbalancer", { port: 80 });

// Need explicit cluster bc we have to define ec2 autoscaling group
const cluster = new awsx.ecs.Cluster("ec2-cluster");

cluster.createAutoScalingGroup("ec2-cluster-asg", {
  templateParameters: { minSize: 2 },
  launchConfigurationArgs: { instanceType: "t2.nano" },
});

// Will build our app image and push to ECR
const appImage = awsx.ecs.Image.fromPath("app-docker-image", "./app");

const appService = new awsx.ecs.EC2Service("app", {
  cluster,
  taskDefinitionArgs: {
    containers: {
      app: {
        image: appImage,
        portMappings: [lb],
        memoryReservation: 256,
      },
    },
  },
  desiredCount: 2,
});

export const url = lb.endpoint;
When I go to
pulumi up
I get an error creating the autoscale group cloudformation stack
Copy code
error waiting for CloudFormation Stack creation: failed to create CloudFormation stack, rollback requested (ROLLBACK_COMPLETE): ["The following resource(s) failed to create: [Instances]. Rollback requested by user." "Property AvailabilityZones cannot be empty."]
I'm under the impression auto scaling would be using the clusters azs? Not seeing a good place to specify the az either, so I think I'm missing something? Any help would be much appreciated!
b
this doesn't look to be supported with awsx at the moment. You'd need ro construct the ec2 instances manually, there's an example of that here: https://github.com/jaxxstorm/pulumi-examples/blob/main/typescript/aws/ecs/index.ts
actually, I think I'm wrong - you'd need to specify the subnets which would scheduled across AZs https://github.com/pulumi/pulumi-awsx/blob/master/nodejs/awsx/ecs/ec2Service.ts#L86
a
Thank you. I will try these after work and follow up. first one looks promising since im seeing asg role doesn't have cloudwatch perms