Skip to content

Commit

Permalink
fix(lambda): environment var values are strings (aws#3858)
Browse files Browse the repository at this point in the history
* fix(lambda): environment var values are strings

AWS Lambda requires that all environment variables will be
strings but the API indicated `any` as the type of the value.
If users would pass in a non-string value, they would see an
error only during deployment.

Fixes aws#3337

* remove redundant null-check on this.environment

* add breaking change excludes
  • Loading branch information
Elad Ben-Israel authored and mergify[bot] committed Aug 29, 2019
1 parent a09203a commit f892312
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ removed:@aws-cdk/aws-apigateway.HttpIntegration.props
removed:@aws-cdk/aws-apigateway.Integration.props
removed:@aws-cdk/aws-apigateway.LambdaIntegration.props
removed:@aws-cdk/aws-apigateway.MockIntegration.props
incompatible-argument:@aws-cdk/aws-lambda.Function.<initializer>
incompatible-argument:@aws-cdk/aws-lambda.SingletonFunction.<initializer>
incompatible-argument:@aws-cdk/aws-lambda.Function.addEnvironment
10 changes: 3 additions & 7 deletions packages/@aws-cdk/aws-lambda/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface FunctionProps {
*
* @default - No environment variables.
*/
readonly environment?: { [key: string]: any };
readonly environment?: { [key: string]: string };

/**
* The runtime environment for the Lambda function that you are uploading.
Expand Down Expand Up @@ -392,7 +392,7 @@ export class Function extends FunctionBase {
/**
* Environment variables for this function
*/
private readonly environment?: { [key: string]: any };
private readonly environment: { [key: string]: string };

constructor(scope: Construct, id: string, props: FunctionProps) {
super(scope, id, {
Expand Down Expand Up @@ -491,11 +491,7 @@ export class Function extends FunctionBase {
* @param key The environment variable key.
* @param value The environment variable's value.
*/
public addEnvironment(key: string, value: any): this {
if (!this.environment) {
// TODO: add metadata
return this;
}
public addEnvironment(key: string, value: string): this {
this.environment[key] = value;
return this;
}
Expand Down

0 comments on commit f892312

Please sign in to comment.