-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cli: hotswapping Lambda environment variable with tokens results in an error #22088
Copy link
Copy link
Closed
Closed
Copy link
Labels
bugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.package/toolsRelated to AWS CDK Tools or CLIRelated to AWS CDK Tools or CLI
Description
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
- Deploy the stack below
- Change
someLiteral: '1'tosomeLiteral: '2'to trigger a hotswap - run
cdk deploy --hotswapand 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.package/toolsRelated to AWS CDK Tools or CLIRelated to AWS CDK Tools or CLI