https://pulumi.com logo
Title
t

thousands-area-40147

02/15/2022, 2:17 PM
Heyo, on destroying a stack that had Lambda functions created as described in the Crosswalk for AWS section, how can I make it so the implicitly generated Cloudwatch log groups for these Lambdas are destroyed as well?
b

billions-processor-3086

02/15/2022, 2:20 PM
someone else may know something i don't here, but since those log groups aren't created until the function executes i don't believe Pulumi would have any way of knowing they exist or what they're named
t

thousands-area-40147

02/15/2022, 2:21 PM
Ah, hm, so it's entirely an AWS thing
Thanks for the answer!
b

billions-processor-3086

02/15/2022, 2:21 PM
sure thing
p

proud-art-41399

02/21/2022, 5:36 AM
You have to create the log group after the Lambda function and explicitly set a dependency. In Python:
my_lambda_log_group = aws.cloudwatch.LogGroup(
    "my-lambda",
    retention_in_days=30,
    name=my_lambda.name.apply(
        lambda name: f'/aws/lambda/{name}'
    ),
    opts=pulumi.ResourceOptions(depends_on=[my_lambda])
)
This way it's also possible to set e.g. retention which would otherwise be 1 month by default.
🙌 1
The only downside is that you can't come with your own name for the log group, it has to follow the standard naming (i.e.
/aws/lambda/...
)