Hi everyone! I’m facing an issue when trying to re...
# aws
t
Hi everyone! I’m facing an issue when trying to reference an AWS ECS Cluster from another stack. I have a stack that exports the id of that cluster and another one that should use that cluster when creating an ECS FargateService. I tried to use get method to get that cluster by id, but the type of the cluster that’s being returned
aws.ecs.Cluster
is not compatible with what’s required when creating an ECS FargateService
awsx.ecs.Cluster
. Any suggestions / guidance would be appreciated, thanks in advance! (more details in 🧵 )
This is how I’m exporting the id from the first stack:
Copy code
const cluster = new awsx.ecs.Cluster(...);

export const clusterId = cluster.id;
b
Take a look at Stack references: https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences This means you can access the outputs from one stack in another
Also worth noting is that AWSX masks a lot of the underlying AWS provider to make it easier to set up. However, it can get a little trickier (but not impossible) to have the two work together
t
I’m already using
StackReference
. This is how I’m importing the id and trying to create an ECS FargateService:
Copy code
const services = new pulumi.StackReference("stack");
const clusterId = services.getOutput("clusterId");
const cluster = aws.ecs.Cluster.get("name", clusterId);

const server = new awsx.ecs.FargateService("resourceName", {
  cluster, // This doesn't work
});
I’m getting a typescript error that says
aws.ecs.Cluster
is not compatible with
awsx.ecs.Cluster
b
That's what I mean. They're not interchangeable.
AWSX is there to get you started. Once you're starting to look at more complicated setups you're going to have to look at the base AWS provider
t
Got it, thanks! do I need to switch to using the AWS core package in this case? Is there an easier way to accomplish the same result? I tried to search for a cluster method in AWSX similar to the one for
awsx.ec2.Vpc
fromExistingIds that returns
Vpc
of type AWSX, but couldn’t find something similar for the cluster
b
do I need to switch to using the AWS core package in this case?
Sorry to say this, but "it depends". There are some cases where it's going to be fine to use AWSX - like if you're using it all within the same stack, if you're not building anything particularly complicated etc and if you can stay within the resources that the package provides.
Otherwise it's best to start looking at the main AWS package
t
I guess in our case we need to use AWS core package for some resources (resources that need the above cluster). Thanks again!
a
Have you tried cluster.arn instead of cluster.id?
t
No, what will be the advantage in this case? creating a fargate service in AWSX requires passing the entire cluster not only the id/arn
b
Was thinking about this last night. Since this is just a typescript object, you could create the object yourself and pass it in
So get the information using the get method you specified before and creating the object with that information
t
hmm, that’s a good idea, but I don’t think this would work because cluster properties are read-only so I can’t do something like this:
Copy code
const cluster = aws.ecs.Cluster.get(`${stackName}-cluster`, config.appClusterId);

const appCluster: awsx.ecs.Cluster;
appCluster.id = cluster.id;
b
But you could do something like:
Copy code
const cluster = aws.ecs.Cluster.get(`${stackName}-cluster`, config.appClusterId);

let appCluster = {
    id: cluster.id
    ...
}
It's the shape that's important (or at least that's my understanding)
t
Thanks again! I think this should work but it requires filling out other properties like security groups that need to be exported from the first stack. Back to your first point, luckily, I found out that I only need to replace two resources to use the AWS core package instead of AWSX and i’m not seeing any issue with this approach so far. So, I think I will go with it
b
I would advise going with the base provider rather than AWSX in this case, but you know how to move on if you wanted to use AWSX
👍 1