Dpl lambda with multiple environment variables

Hi, I can’t figure out how to specify multiple environment variables in the dpl to deploy a lambda.

I use .travis.yml to call a bash script (deploy.lambdas.sh) and have the environment variables in a bash variable. The docu says “List of Environment Variables to add to the function — type: string or array of strings” and it is unclear to me how to specify an “array of strings”

part of .travis.yml:

- provider: script
  edge: true
  script: >-
          bash deployConfig/deploy.lambdas.sh

part of deployConfig/deploy.lambdas.sh:

echo "using defaultEnvVars ${defaultEnvVars}"
echo "using customEnvVars ${customEnvVars}" # todo: fix multiple vars
# Deploy
echo "deploying lambda ${featureName}..."
dpl --provider="lambda" \
  --access_key_id="${accessKey}" \
  --secret_access_key="${secretKey}" \
  --region="${awsRegion}" \
  --function_name="${featureName}" \
  --role="${lambdaRole}" \
  --environment="${customEnvVars} ${defaultEnvVars}" \
  --description="Travis build #$TRAVIS_BUILD_NUMBER ($TRAVIS_REPO_SLUG $TRAVIS_BRANCH $shortCommit)" \
  --runtime="${runtime}" \
  --zip="${zipFileDir}/${zipFileName}" \
  --layers="${layerArns}" \
  --timeout="${timeout}" \
  --memory_size="${memorySize}" \
  --handler_name="${handler}" || exit 1;
echo "done deploying lambda ${featureName}."

The log shows:

using defaultEnvVars vecfg={"envs":[{"name":"ve-cd-dev","awsAccountId":"[secure]","datalakeS3Bucket":"[secure]","slackWebhookUrl":"[secure]"}]}
using customEnvVars "datalakeEtlDataPrefix=etl" "datalakeRawDataPrefix=raw"
deploying lambda derControl...
Installing deployment dependencies
Installing gem dependencies: aws-sdk-lambda (~> 1.0), rubyzip (~> 1.2.2)
Using Access Key: AK******************
Setting the build environment up for the deployment
Updating existing function derControl.
1 validation error detected: Value at 'environment.variables' failed to satisfy constraint: Map keys must satisfy constraint: [Member must satisfy regular expression pattern: [a-zA-Z]([a-zA-Z0-9_])+]
Script failed with status #<struct Dpl::Provider::Status provider=Dpl::Providers::Script, status=:stable, info=nil>
failed to deploy

Any assistance is appreciated.

One of these values is wrong.

I’ve figured it out.

Here’s my one liner dpl command:

dpl ${dplCmd1} --access_key_id="${accessKey}" --secret_access_key="${secretKey}" ${dplCmd2} ${dplCmd3} ${dplCmdEnvs} ${dplCmdLayers} --description="Travis build #$TRAVIS_BUILD_NUMBER ($TRAVIS_REPO_SLUG $TRAVIS_BRANCH $shortCommit)" || exit 1;

The content of the dplCmdEnvs is

--environment=vecfg={"envs":[{"name":"ve-cd-dev","awsAccountId":"[secure]","datalakeS3Bucket":"[secure]","iotEndpoint":"[secure]","gqlJwtSecret":"[secure]","gqlUrl":"[secure]","slackWebhookUrl":"[secure]","plivoAuthId":"[secure]","plivoAuthToken":"[secure]"}]} --environment=datalakeEtlDataPrefix=etl --environment=datalakeRawDataPrefix=raw

I’ve looked at GitHub - travis-ci/dpl at v2.0.2.beta.1 where it seems to be suggested that the environment can be a string and can be given multiple times (or an array)

--environment VARS List of Environment Variables to add to the function (type: array (string, can be given multiple times), alias: environment_variables, format: /[\w\-]+=.+/, note: Can be encrypted for added security)

The other day I looked at Lambda Deployment - Travis CI which didn’t mention that it can be ‘given multiple times’.