DEV Community

Cover image for Amazon EventBridge API Destinations with parametrized endpoint URL and Mailchimp integration

Amazon EventBridge API Destinations with parametrized endpoint URL and Mailchimp integration

Pawel Zubkiewicz on April 06, 2021

I love ❤️ working with Amazon EventBridge service. This is not a big surprise as it is beloved by the community. However, for me, it's not just the...
Collapse
 
seththomas profile image
Seth Geoghegan

Great post! The most thorough coverage of the topic I've seen to date, thanks for taking the time to put it together.

Based on my reading of this topic, it sounds like API Destinations only provide one-way communication with 3rd party APIs. Every example I've seen so far is sending event notifications to external APIs (e.g. a POST request to a ticketing system, sending mail, etc). None of these examples show how to fetch data from a 3rd party API in response to an event. Do you know if this is possible?

Here's some context to why I'm asking. My application ingests webhook notifications from activity tracker APIs (e.g. Strava, Fitbit, etc). The events themselves are just notifications that an activity happened (time, event ID, user id). To get more information from the API, I need to issue a GET request to the 3rd party API and process the response. I'd love if I could use Event Bridge and API Destinations to automatically fetch data in response to webhook events being sent into my system. However, this doesn't sound possible with the current EventBridge offering.

Collapse
 
pzubkiewicz profile image
Pawel Zubkiewicz

Thank you Seth.

You're correct. This mechanism works in just a one way (from AWS to a 3rd party endpoint).

As it goes about your application you may research AWS API Gateway service. This example serverlessrepo.aws.amazon.com/appl... shows how to implement a webhook that sends info to SNS. You may replace SNS with EventBridge to have single messaging channel.

Collapse
 
rcoundon profile image
Ross Coundon

We're just investigating this as a means of rate limiting requests to a 3rd party API from lambda.
There is an option in the API Destination HTTP Method for GET requests, does this mean it is possible to retrieve data using this method?

Collapse
 
boyney123 profile image
David Boyne

Nice write-up Pawel, thanks for taking the time and the examples given.

I personally love this feature and cannot wait to get my hands on it with a use case and start using it. This is the future for sure!

Collapse
 
pzubkiewicz profile image
Pawel Zubkiewicz

Thans a lot, David. Yes, this functionality is cool.

When I will have some free time I will add integration with my private Slack channel to get notifications about new customers.

James Beswick shared code that does that: github.com/aws-samples/serverless-...

Collapse
 
neophytte profile image
neophytte

No matter what I do, I can't seem to get the MailChimp API endpoint to work; initially I was getting a 404 with InvocationEndpoint set as ${self:custom.webhook.endpoint}/lists/${self:custom.mailchimp.list}/segments//members* - then I set the endpoint to ${self:custom.mailchimp.endpoint}/lists/${self:custom.mailchimp.list}/members (which directly writes to a list), and modified the JSON payload to:

              InputTemplate: >
                {
                  "email_address": <email>,
                  "status": "subscribed",
                  "interests": {
                    "0ce6ed21da": true
                  }
                }

which works when submitted via Thunderclient or Postman, but shows an error in the attributes SDK_CLIENT_ERROR with Unable to invoke ApiDestination endpoint: The request failed due to an internal validation error. - is there anyway to uncover what the actual error is for the validation?

Collapse
 
davidbrown722 profile image
davidbrown722

I absolutely share your enthusiasm for Amazon EventBridge—it's like stepping into a sci-fi adventure every time you use it! Your article on integrating EventBridge with Mailchimp sounds incredibly insightful and groundbreaking. The ability to use HTTP Path Parameters to dynamically trigger endpoints is such a game-changer and not often highlighted in documentation. Plus, your real-world application with Mailchimp and tagging users based on event messages is both clever and practical. Can’t wait to dive into this tutorial through flare leggings and experience the excitement for myself.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
neophytte profile image
neophytte

Found it ... sls = serverless:

npm install serverless --global

Collapse
 
gkgourav45 profile image
gkgourav45

Additional info
It is not possible to define what a successful call means for retry. EventBridge will assume this from the returned HTTP status code

Collapse
 
gkgourav45 profile image
gkgourav45

Is it possible to store api calls and their response?