Cdk watch expects an environment variable to be a string while it is already a string

Viewed 36

This error occasionally occurs on "cdk watch" and disappears when I destroy and redeploy the stack. All the global and per lambda variables are strings for sure. The table name is not declared explicitly but generated from the id..(maybe this is the cause of the issue?)

    export class MyStack extends Stack {
    constructor(app: App, id: string, props: MyStackProps) {
    super(app, id);

    const isProd = props.deploymentEnv;
    const stackName = Stack.of(this).stackName;
    const PRIMARY_KEY = 'reportId';

    const dynamoTable = new Table(this, `MyTable-${stackName}`, {
      partitionKey: {
        name: PRIMARY_KEY,
        type: AttributeType.STRING,
      },
      stream: StreamViewType.NEW_IMAGE,
      removalPolicy: isProd ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY,
    });
    // Default props for lambda functions
    const nodeJsFunctionProps: NodejsFunctionProps = {
      bundling: {
        externalModules: [
          'aws-sdk', // Use the 'aws-sdk' available in the Lambda runtime
          '@sparticuz/chrome-aws-lambda',
        ],
      },
      depsLockFilePath: join(__dirname, '../package-lock.json'),
      environment: {
        PRIMARY_KEY: PRIMARY_KEY,
        TABLE_NAME: dynamoTable.tableName,
      },
      runtime: Runtime.NODEJS_16_X,
    };

In the lambda file, I'm getting the variables this way:

    const TABLE_NAME = process.env.TABLE_NAME ?? '';

The error:

failed: InvalidParameterType: Expected params.Environment.Variables['TABLE_NAME'] to 
be a string
0 Answers
Related