Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS lambda create-function accepts only one environment variable

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?

like image 596
Angela Avatar asked Mar 26 '17 01:03

Angela


2 Answers

You should try with Variables="{KeyName1=string,KeyName2=string}"

like image 51
DaMaill Avatar answered Nov 16 '22 02:11

DaMaill


The other option is to put the environment variables in a json file (ex: environment.json) and use that instead... and: % aws lambda update-function-configuration --function-name MyLambda --environment file://environment.json

... or ... you could also use the file://environment.json command in your create-lambda statement

like image 1
Tom Avatar answered Nov 16 '22 01:11

Tom