When creating a Lambda function, it's not very hard to encrypt an environment variable via the GUI console. I just enter the key value pairs, then open the encryption helper and enter the ARN of my KMS key. This allows me to encrypt the value, so it's encrypted before it's sent to be stored, as shown in the image above.
What I'm trying to accomplish is this exact same thing, but assuming you're deploying that Lamba function not in the GUI console, but via a CloudFormation template, which is getting deployed in the CLI.
Here's how I'm specifying the relevant Parameters in the CloudFormation template:
"EnvironmentVariable" : {
"Type" : "String",
"Default" : "test",
"Description" : "Environment Variable"
},
"KmsKeyArn" : {
"Type" : "String",
"Description" : "KMS Key ARN if environment variables are encrypted"
},
Here's how I'm referencing those parameters in the Lambda resource, in the Resources section of the template:
"Environment" : {
"Variables" : {
"SomeVariable": {
"Ref" : "EnvironmentVariable"
}
}
},
"KmsKeyArn" : { "Ref" : "KmsKeyArn" },
And here's how I'm deploying this template in the CLI (with all my ARN and other values changed to protect privacy, but maintaining their structure):
aws cloudformation deploy --template-file lambda-template.json --stack-name "CLI-lambda-stack" --parameter-overrides S3BucketName="theBucket" S3FileLocation="lambda_function.zip" S3ObjectVersion="ZuB0eueEgh2yh5q00.DiykLNudujdsc5" DeadLetterArn="arn:aws:sns:us-west-2:526598937246:CloudFormationTests" EnvironmentVariable="testing" KmsKeyArn="arn:aws:kms:us-west-2:227866537246:key/b24e7c79-a14d-4a3e-b848-165115c86210" HandlerFunctionName="lambda_function.lambda_handler" MemorySize="128" Role="arn:aws:iam::507845137246:role/serverless-test-default-us-east-1-lambdaRole" FuncName="myCLILambda"
After running this in the CLI, I get no errors, but when I open the Lambda function in the console to inspect the results, I see something like this:
Where am I going wrong? Thanks for any insights.
KmsKeyArn
property on the aAWS::Lambda::Function
is strictly for customer master key. That being said, why can you not use this kind of key? I was not able to understand why you need the default aws/lambda key. – tyronEnvironmentVariable
. – tyron