5

I'm trying to write a CloudFormation template that subscribes a Lambda function to a CloudWatch Logs LogGroup. This Lambda function should then parse the logs and put them in to an Amazon ES cluster.

The subscription etc. is all working nicely, but the one bit I can't get my head around is how to pass in the Amazon ES cluster endpoint to the Lambda function. The template that AWS provides when you walk through the console includes a line:

var endpoint = 'my-aws-es-endpoint.amazonaws.com';

I'll obviously need to update this each time the CloudFormation template runs, as each time I'll get a different cluster with a different end point. I don't want to manually update this, but want to be able to use CloudFormation functions like 'Fn::GetAtt' to get the end point and pass it in to Lambda. I just can't figure out how.

user1799
  • 81
  • 1
  • 3
  • 6

1 Answers1

6

You can pass ES cluster endpoint to Lambda function as an environment variable. Here is a snippet of CloudFormation template for such function:

"mylambda": {
  "Type": "AWS::Lambda::Function",
  "Properties": {
    "Handler": "index.handler",
    "Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] },
    "Code": {
      "S3Bucket": "my-lambda-functions-bucket",
      "S3Key": "mylambda.zip"
    },
    "Runtime": "nodejs4.3",
    "Timeout": "25",
    "Environment": {
       "Variables": {
         "ESENDPOINT": { "Fn::GetAtt": ["ESDOMAINRESOURCE", "DomainEndpoint"] }
       }
    }
  }
}
dsmsk80
  • 5,757
  • 17
  • 22