https://pulumi.com logo
#general
Title
# general
e

eager-cartoon-54068

04/14/2020, 10:48 PM
Is there a way to get or create a resource? I’m trying to add a Cloudwatch log group subscription to a log group that may or may not exist when I deploy to different regions and accounts. When I try:
Copy code
let batchLogGroup = null;
    try {
        batchLogGroup = aws.cloudwatch.LogGroup.get(`batch-log-group-${region}`, '/aws/batch/job', {},  {provider})
    } catch (e) {
        batchLogGroup = new aws.cloudwatch.LogGroup(`batch-log-group-${region}`, {name: "/aws/batch/job", retentionInDays: 7}, {provider})
    }
I get `error:
Preview failed: resource ‘/aws/batch/job’ does not exist
.
f

faint-table-42725

04/14/2020, 11:31 PM
Please see this issue: https://github.com/pulumi/pulumi/issues/3364#issuecomment-602898866 — you can use the workaround suggested by @white-balloon-205 in the comment to use
aws.cloudwatch.getLogGroup
instead of
.get
e

eager-cartoon-54068

04/15/2020, 12:25 PM
thanks!