Reputation: 311
I have terraform code which creates a Lambda function. I then have some ruby code that is the lambda function. I can not figure out, or find any information in how to actually use the variables which are being passed in from the terraform into the lambda. I ultimately just need to know how to use the terraform variables in the ruby lambda function
I have found examples in python and JS. There is little similarities.
Here is my terraform code
resource "aws_lambda_function" "send_sns_lambda" {
filename = "statuslambda.zip"
function_name = "status-page-send-sns"
source_code_hash = "${data.archive_file.status_lambdas.output_base64sha256}"
role = "${aws_iam_role.status_lambda.arn}"
handler = "statusLambda.send_sns"
runtime = "ruby2.5"
vpc_config = {
subnet_ids = ["subnet-xxxx", "subnet-xxxxx"]
security_group_ids = ["sg-xxxxxx"]
}
environment = {
variables = {
status = "Major Outage"
}
}
}
And my Lambda function
def send_sns(event:,context:)
sns = Aws::SNS::Resource.new(region: 'us-xxx-xxx')
topic = sns.topic('arn:aws:sns:us-east-1:xxxxxxxx')
topic.publish({
message: '#{status}'
})
end
The idea is that the status
variable in terraform gets passed into the status variable in the ruby code
Here is the python example I have found
import os
def lambda_handler(event, context):
return "{} from Lambda!".format(os.environ['greeting'])
Upvotes: 0
Views: 601
Reputation: 37590
So your question is "how to access environment variables in Ruby"? That would be ENV['status']
.
Upvotes: 2