Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Pass env vars when invoking lambda #708

@richardwu

Description

@richardwu

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.

Metadata

Metadata

Assignees

Labels

closed-for-stalenessThis issue was closed because it didn't receive updatesfeature-requestNew feature or requestlambdaresponse-requestedThis issue requires a response to continueservice-apiThis issue pertains to the AWS API

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions