Skip to content

Add lambda code for replace API Destination#1

Open
ramgopalsiddh wants to merge 5 commits intooptiowl-cloud:mainfrom
ramgopalsiddh:add-lambda-function
Open

Add lambda code for replace API Destination#1
ramgopalsiddh wants to merge 5 commits intooptiowl-cloud:mainfrom
ramgopalsiddh:add-lambda-function

Conversation

@ramgopalsiddh
Copy link
Copy Markdown

@ramgopalsiddh ramgopalsiddh commented Aug 5, 2024

  • This Lambda is used to replace API Destination.

  • Why use this Lambda?

    • Because API Destination has a 5-second timeout limit.
    • Replace API Destination with Lambda and increase the timeout to 15 minutes.
  • In this function, use AWS SQS as the source and this Lambda function as the target. This Lambda receives messages from SQS and sends them to the webhook.

In This we have Go lang and Python 2 language code

processed_message_ids.add(message_hash)

# Forward the entire SQS message to the external API
response = requests.post('https://webhook.site/f7274881-d5c1-43f3-9a30-de0a0a255cdd', json=record)
Copy link
Copy Markdown
Contributor

@eightnoteight eightnoteight Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the webhook URL need to be given from the UI itself, record body etc,...

Copy link
Copy Markdown
Author

@ramgopalsiddh ramgopalsiddh Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • we have 2 way to Add URL from UI :-
    1.Add URL in Lambda Environment variables
    2. Send URL with SQS message and extract that url in Lambda function and use it
    3. We can use Parameter Store, Webhook URL store in Parameter Store and use url from Parameter Store

Copy link
Copy Markdown
Author

@ramgopalsiddh ramgopalsiddh Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This code in Go lang this Lambda function is used to replace API Destination
  • In this we enter url in SQS message like this
    • {
      "url": "< url >",
      "message_body": "This is a simple text message."
      }
  • This help us to easy to change url without change in code

var processedMessageIDs = make(map[string]struct{})

// Record represents an SQS record
type Record struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should replace API Destination in a generic way i.e we should accept all kinds of records i.e not just SQS

var records []Record

// Determine the type of event and unmarshal accordingly
switch e := event.(type) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any standard event type that we can accept directly in the handler, probably input transformer is a good feature to checkout for this lambda target

@ramgopalsiddh
Copy link
Copy Markdown
Author

  • Now the code is more generic and will work on also other than SQS.
  • Added FORWARD URL in Lambda Environment variables that is safe & easy to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants