How might I set the log group parameters on a pulu...
# general
e
How might I set the log group parameters on a pulumi lambda function resource? i would like my lambda logs to only persist for a week instead of default never
l
Create the log group manually, instead of letting lambda create one for you. There's an example in the docs: https://www.pulumi.com/registry/packages/aws/api-docs/lambda/function/#cloudwatch-logging-and-permissions
m
example in typescript
Copy code
const lambdaFunctionApi = new aws.lambda.Function(
  `${appName}-api`,
  { handler: "lambdaApiHandler.handler", ...lambdaFunctionArgs, ...lambdaAdditionalFunctionArgs },
  { dependsOn: [applicationRole] },
);

lambdaFunctionApi.name.apply(
  lambdaFunctionName =>
    new aws.cloudwatch.LogGroup(`${appName}-function-api-lg`, {
      name: `/aws/lambda/${lambdaFunctionName}`,
      retentionInDays: 14,
    }),
);
l
Can I suggest that creating the log group inside an
apply()
could be avoided thus:
Copy code
new aws.cloudwatch.LogGroup(`${appName}-function-api-lg`, {
      name: pulumi.interpolate`/aws/lambda/${lambdaFunctionApi.name}`,
      retentionInDays: 14,
    });
m
We tried something like that a while ago and had issues, so we landed on the
apply()
. Thank you for the tip, because it would be nice to drop those applys in favor of interpolation.
e
wont the lambda create the log group then the new aws.cloudwatch.LogGroup will fail due to the log group already existing?