question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Environment variable parsing of CDK lambda is not working properly

See original GitHub issue

🐛 Bug Report

What is the problem?

When using environment variables to define lambda function, the value will become totally different in AWS console panel.

Reproduction Steps

  1. Define a TIMETABLE variable with 17:00 string.

    const lambdaFn = new lambda.Function(this, 'Singleton', {
      environment: {VALUE: 123, 'TIMETABLE': '17:00'}
    });
    
  2. Generate template.yaml.

    cdk synth --no-staging > template.yaml
    

    And the TIMETABLE seems weird from here.

    SingletonXXXXXXX:
      Type: AWS::Lambda::Function
      Environment:
        Variables:
          VALUE: "123"
          TIMETABLE: 17:00
    
  3. Go to lambda function of AWS console panel, and the value of environment variable TIMETABLE is 1020.

Environment

  • CDK CLI Version: 1.6.1
  • Module Version: 1.6.1
  • OS: OSX Mojave
  • Language: TypeScript

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nija-atcommented, Oct 1, 2019

It’s possible that it was fixed in the underlying YAML package we use - https://github.com/eemeli/yaml/.

Possibly this - https://github.com/eemeli/yaml/commit/884fe078566a3c569e3da1112ff21f45830df2fe ?

1reaction
nija-atcommented, Sep 24, 2019

As @rhboyd pointed out, this is coming from the serializing function of the underlying YAML library.

You could use the --json option of cdk synth to generate the output in JSON, or use the one we generate for every synth command that you can find in the cdk.out folder. @tpai - Would this sufficiently mitigate what you’re trying to do here?

cdk deploy uses the JSON format, so this shouldn’t occur when the stack is deployed via the deploy command.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common AWS CDK issues
This topic describes how to troubleshoot the following issues with the AWS CDK.
Read more >
AWS Lambda Environment Variables Best Practices
This blog will show you how to correctly parse, validate, and use your environment variables in your Python AWS Lambda both in deployment ......
Read more >
AWS Lambda Environment Variables Best Practices
In this blog, I will show you how to properly parse, validate and use your environment variables in your Python AWS Lambda. And...
Read more >
Homepage - AWS Lambda Powertools for Python
Utilities might work with web frameworks and non-Lambda environments, though they are not officially supported. Eases the adoption of best practices. The main ......
Read more >
Getting the most of AWS Lambda free compute - wrapper scripts
Tagged with serverless, lambda, aws, cdk. ... The Node.js problem ... Since the environment variables specified for the AWS Lambda function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found