0

I have an AWS Lambda function that creates some route53 records when provided with a domain name as an input/payload. It completes in around 6 mins & takes only one input which is a 'domain name'.

I tried to run this function in slack using AWS ChatOps but looks like ChatOps cant run the function that takes more than 15 seconds. What I am trying is to create some kind of slack bot that will ask for the input/domain name and then run the required lambda function. After this it should provide the output whether the function completed successfully or not.

For example lets say the slack bot name for this task is "Lambda Runner" and below is a sample conversation with that

@Lambda-Runner

-Please type the domain that you want to create route53 records for
* xyz.com (Input from user)
- Processing
- Route53 records has been created for the provided domain

Has anyone ever done this type of task or have any suggestion where I should look for these? Thanks

Faisal Shani
  • 698
  • 1
  • 13
  • 37

1 Answers1

0

First, the maximum timeout for running AWS CLI Commands from AWS Chatbot is 15 seconds.

If you have longer running jobs, you should invoke them asynchronously. For lambda it can be achieved setting the flag invocation-type as 'Event':

aws lambda invoke --invocation-type Event --function-name my_function_name --region us-east-1 --payload "{}" --cli-binary-format raw-in-base64-out response.json

When you invoke a function asynchronously, you don't wait for a response from the function code. You hand off the event to Lambda and Lambda handles the rest.

So, instead of waiting for a response, the user should be notified when the lambda ends its execution. You can add in your lambda function the logic to publish a message (indicating if the route53 record was created successfully or not) to the SNS Topic you Slack Channel is subscribed. In this way, after publishing the message to SNS, it will appear as a Slack message to the user.

Another option is configuring a destination for the asynchronous invocation. In this way you do not need to add in your code the SNS:Publish action. It is done via lambda configuration and mantains decoupled the core logic from configuration.

OARP
  • 3,429
  • 1
  • 11
  • 20