-
Notifications
You must be signed in to change notification settings - Fork 16
Pass env vars when invoking lambda #708
Description
Is your feature request related to a problem? Please describe.
I am invoking (children) lambdas inside another (parent) lambda. The parent lambda is created with SAM (the child lambda as well, in fact the child lambda is exactly the parent lambda but w/ a different Payload
) and has API secrets, passed via environment variables, with --parameter-overrides
.
SAM will initialize the environment variable for the lambda as the Parameter
's name if not overridden.
Concretely, if I have a lambda initialized with the following in SAM:
Parameters:
APIKey:
NoEcho: "true"
Type: String
...
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
API_KEY: !Ref APIKey
MyFunction
calls other instances of MyFunction
as children lambdas:
import { Lambda } from "@aws-sdk/client-lambda";
const client = new Lambda();
await client.invoke({
FunctionName: ...,
InvocationType: "Event",
Payload: ...
});
When I deploy MyFunction
with --parameter-overrides APIKey=XXX
, the parent lambda call is initialized with the correct XXX
value, but when it invokes children lambdas, API_KEY
is set to "APIKey"
(name of SAM parameter).
Describe the solution you'd like
I would like to be able to pass environment variables to inject into the child lambda. E.g.,:
await client.invoke({
FunctionName: ...,
InvocationType: "Event",
Payload: ...,
Environment: {API_KEY: process.env.API_KEY},
});
Describe alternatives you've considered
I'm not too sure if there exists a way to do this already, or if EnvVars/parameter overrides are being used correctly here.
Additional context
Not sure if this should belong here or in the SAM github repo.