Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am trying to use environment variables for my lambda but when I run the following Lambda AWS CLI create-function command from a Gradle task that runs a shell script,

aws $PROFILESTR lambda create-function \

--region us-east-1 \

--function-name MyLambda \

--zip-file fileb://$ZIP \

--role arn:aws:iam::$AWS_ACCT_ID:role/my_lambda \

--handler com.test.MyLambda::handleRequest \

--runtime java8 \

--description "Lambda description..." \

--memory-size 256 \

--timeout 45 \

--environment Variables={DEV_URL=dev,PROD_URL=prod}

it gives me this message and doesn't create the lambda function

:my-lambda:createLambda

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]

To see help text, you can run:

  aws help

  aws <command> help

  aws <command> <subcommand> help

Unknown options: Variables=PROD_URL=prod

:my-lambda:createLambda FAILED

If I remove the second variable (declare only one env variable), it creates the function just fine.

From the lambda create-function cli documentation, the environment option accepts multiple variables:

--environment (structure)

The parent object that contains your environment's configuration settings. Shorthand Syntax:

Variables={KeyName1=string,KeyName2=string}

I should be able to create the lambda through a script and not through AWS console (release should be automated).

What am I missing here or what am I doing wrong?

1 Answer

+1 vote
by (44.4k points)

Try it with this:

Variables="{KeyName1=string,KeyName2=string}"

AWS lambda create-function accepts only one environment variable
Intellipaat-community
by
Thanks, It worked.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
...