This message was deleted.
# aws
s
This message was deleted.
b
I don't think you can even get the instances in an ASG from the AWS SDK. Could you tag the instances (with something like the ASG name) and then use getInstances() and filter by tag?
m
Maybe? I haven’t wrapped my head around how I name or tag the instances in the group yet… I’d like
<appName>-<availabilityZone>
as the name.
b
Looks like if you're using launch templates, you can set them here: https://www.pulumi.com/docs/reference/pkg/aws/ec2/launchtemplate/#tagspecifications_nodejs
m
Yeah, but I’m unsure of how to do interpolation when an instance is created. e.g. I want it to automatically tag it with
Name: <appName>-<availabilityZone>
Potentially I could create the instances and attachment them to a Group, but then I’m bypassing the template, also Pulumi doesn’t support this type of attachment. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.attach_instances https://www.pulumi.com/docs/reference/pkg/aws/autoscaling/attachment/
b
Let me take a look and put together a quick demo to see what's possible
👍 1
Ok, so I got this working. In the example below, you can see that I've tagged the EC2 instance with a tag called
appName
(although you can tag them whatever you want) Then I'm getting the instances using
aws.ec2.getInstances()
(worth noting that the instance data that's returned is not the same as on the
aws.ec2.Instance
resource)
Copy code
const myAppName = "pk-app";

let instances = pulumi.output(aws.ec2.getInstances({
    instanceTags: {
        appName: myAppName
    }
}));

instances.ids.apply(ids => {
    ids.map(id => {
        new aws.cloudwatch.LogGroup(`${appName}-ec2-lg`, {
            name: pulumi.interpolate`/custom/ec2/${myAppName}/${id}`,
            retentionInDays: 14
        })
    })
});
m
Ahh, interesting approach, thank you, I will try it. I think I’ve given up on the ASG route, ran into pitfall after pitfall.