This script, in python or bash, generates vars.json
, a file used when testing locally your lambda function running:
sam local invoke MyLambdaFunction --env-vars vars.json
vars.json
contains the environment variables used by Lambda functions. The structure is as follows:
{
"LambdaFunctionName1": {
"VariableName1": "VariableValue1",
"VariableName2": "VariableValue2",
...
},
"LambdaFunctionName2": {
"VariableName1": "VariableValue1",
"VariableName2": "VariableValue2",
...
},
...
}
Clone the repository to your local machine:
git clone https://github.com/valeriosalvucci/samvars.git
Ensure that
- Your AWS CLI is configured with the necessary credentials
- The cloludformation is deployed. samvars gets the parameter value from the deployed cloudformation.
Requirements
- Python 3.x
- AWS CLI configured with the necessary credentials
- boto3, toml
Install the required dependencies:
pip install -r requirements.txt
sam-app$ python samvars.py [ --stack-name YourCloudFormationStackName ]
Run the script by executing the following command:
sam-app$ sh samvars.sh [ --stack-name YourCloudFormationStackName ]
If the --stack-name parameter is omitted, the script will attempt to read the CloudFormation stack name from samconfig.toml. If samconfig.toml file is not present or does not contain the necessary information, the script will prompt you to enter the CloudFormation stack name manually.