AWS CDK how to to Set Up Lambda Function Environment Variables with Secrets Manager
I'm wondering if anyone has experience with I'm trying to configure an AWS Lambda function using AWS CDK (version 2.30.0) to pull sensitive environment variables from AWS Secrets Manager... However, I'm working with an scenario where the Lambda function does not seem to receive the environment variables, resulting in the function failing to authenticate. I have the following snippet in my `lib/my-stack.ts`: ```typescript import * as cdk from 'aws-cdk-lib'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'; const secret = new secretsmanager.Secret(this, 'MySecret', { secretName: 'mySecretName', }); const myFunction = new lambda.Function(this, 'MyFunction', { runtime: lambda.Runtime.NODEJS_14_X, code: lambda.Code.fromAsset('lambda'), handler: 'index.handler', environment: { SECRET_ARN: secret.secretArn, }, }); secret.grantRead(myFunction); ``` The Lambda function is defined correctly, and I have verified that the secret exists in Secrets Manager. However, when I run the function, I get the following behavior: ``` behavior: Missing required environment variable: SECRET_ARN ``` I confirmed that the secret's ARN is being set correctly, but it seems like the environment variable is not recognized at runtime. I attempted to log the environment variables using `console.log(process.env)` within my Lambda function, but the output does not contain `SECRET_ARN`. I've also tried deploying the stack multiple times, and I checked that the IAM role attached to the Lambda function has the correct permissions to access the secret. Is there something I'm missing in the AWS CDK setup, or could it be an scenario with how the environment variables are being processed? This is part of a larger API I'm building. Any ideas what could be causing this? I'm developing on Linux with Typescript. Any ideas what could be causing this?