Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: hotswapping Lambda environment variable with tokens results in an error #22088

Closed
tmokmss opened this issue Sep 17, 2022 · 2 comments · Fixed by #22099
Closed

cli: hotswapping Lambda environment variable with tokens results in an error #22088

tmokmss opened this issue Sep 17, 2022 · 2 comments · Fixed by #22099
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Sep 17, 2022

Describe the bug

Hi I found the following issue regarding hotswap. I'll dig into the actual code to find the root cause later.

Expected Behavior

Hotswap successes.

Current Behavior

When hotswapping, the error below happens.

 ❌  SampleStack failed: InvalidParameterType: Expected params.Environment.Variables['someToken'] to be a string
    at ParamValidator.fail (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:50:37)
    at ParamValidator.validateType (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:233:10)
    at ParamValidator.validateString (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:155:32)
    at ParamValidator.validateScalar (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:131:21)
    at ParamValidator.validateMember (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:95:21)
    at ParamValidator.validateMap (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:118:14)
    at ParamValidator.validateMember (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:93:21)
    at ParamValidator.validateStructure (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:76:14)
    at ParamValidator.validateMember (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:89:21)
    at ParamValidator.validateStructure (/Users/cdk/sample/node_modules/aws-sdk/lib/param_validator.js:76:14) {
  code: 'InvalidParameterType',
  time: 2022-09-17T02:35:50.431Z
}

 ❌ Deployment failed: Error: Stack Deployments Failed: InvalidParameterType: Expected params.Environment.Variables['someToken'] to be a string
    at deployStacks (/Users/cdk/sample/node_modules/aws-cdk/lib/deploy.ts:61:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at CdkToolkit.deploy (/Users/cdk/sample/node_modules/aws-cdk/lib/cdk-toolkit.ts:312:7)
    at initCommandLine (/Users/cdk/sample/node_modules/aws-cdk/lib/cli.ts:349:12)

Stack Deployments Failed: InvalidParameterType: Expected params.Environment.Variables['someToken'] to be a string

Reproduction Steps

  1. Deploy the stack below
  2. Change someLiteral: '1' to someLiteral: '2' to trigger a hotswap
  3. run cdk deploy --hotswap and you can see the above error.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';

export class SampleStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const role = new Role(this, 'Role', {
      assumedBy: new ServicePrincipal('sns.amazonaws.com'),
    });

    new lambda.Function(this, 'Function', {
      code: lambda.Code.fromInline('exports.handler=()=>{}'),
      runtime: lambda.Runtime.NODEJS_16_X,
      handler: 'index.handler',
      environment: {
        someToken: role.roleArn,
        someLiteral: '1',
      },
    });
  }
}

Possible Solution

No response

Additional Information/Context

Lambda environment variable hotswap was introduced in #21532.

CDK CLI Version

2.42.0

Framework Version

2.42.0

Node.js Version

16.13.1

OS

macOS

Language

Typescript

Language Version

No response

Other information

No response

@tmokmss tmokmss added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Sep 17, 2022
@zxkane
Copy link
Contributor

zxkane commented Sep 17, 2022

met the same issue when running cdk deploy --watch,

change the env of lambda reproducing the issue.

The workaround is deploying the changes without --watch option via cdk deploy only.

@mergify mergify bot closed this as completed in #22099 Sep 19, 2022
mergify bot pushed a commit that referenced this issue Sep 19, 2022
closes #22088 

We always need to use `evaluateCfnTemplate.evaluateCfnExpression` when a variable to be used in hotswap may contain tokens.

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https:/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https:/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https:/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

homakk pushed a commit to homakk/aws-cdk that referenced this issue Dec 1, 2022
)

closes aws#22088 

We always need to use `evaluateCfnTemplate.evaluateCfnExpression` when a variable to be used in hotswap may contain tokens.

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https:/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https:/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https:/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants