Skip to content

Commit

Permalink
fix: Ensure AWS env vars in local invocation made with docker (#7349)
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenbonito committed Feb 19, 2020
1 parent b05b934 commit c09f718
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/plugins/aws/invokeLocal/index.js
Expand Up @@ -434,13 +434,27 @@ class AwsInvokeLocal {
]).then(results => {
const imageName = results[1];
const artifactPath = results[2];

const lambdaName = this.options.functionObj.name;
const memorySize =
Number(this.options.functionObj.memorySize) ||
Number(this.serverless.service.provider.memorySize) ||
1024;
const lambdaDefaultEnvVars = {
AWS_REGION: this.provider.getRegion(),
AWS_DEFAULT_REGION: this.provider.getRegion(),
AWS_LAMBDA_LOG_GROUP_NAME: this.provider.naming.getLogGroupName(lambdaName),
AWS_LAMBDA_FUNCTION_NAME: lambdaName,
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: memorySize,
};
const configuredEnvVars = this.getConfiguredEnvVars();
const envVarsFromOptions = this.getEnvVarsFromOptions();
const envVars = _.merge(configuredEnvVars, envVarsFromOptions);
const envVars = _.merge(lambdaDefaultEnvVars, configuredEnvVars, envVarsFromOptions);
const envVarsDockerArgs = _.flatMap(envVars, (value, key) => [
'--env',
`${key}=${value}`,
]);

const dockerArgsFromOptions = this.getDockerArgsFromOptions();
const dockerArgs = _.concat(
['run', '--rm', '-v', `${artifactPath}:/var/task`],
Expand Down
10 changes: 10 additions & 0 deletions lib/plugins/aws/invokeLocal/index.test.js
Expand Up @@ -1164,6 +1164,16 @@ describe('AwsInvokeLocal', () => {
'-v',
'servicePath:/var/task',
'--env',
'AWS_REGION=us-east-1',
'--env',
'AWS_DEFAULT_REGION=us-east-1',
'--env',
'AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/hello',
'--env',
'AWS_LAMBDA_FUNCTION_NAME=hello',
'--env',
'AWS_LAMBDA_FUNCTION_MEMORY_SIZE=1024',
'--env',
'providerVar=providerValue',
'--env',
'functionVar=functionValue',
Expand Down

0 comments on commit c09f718

Please sign in to comment.