Seth Geoghegan
04/01/2022, 4:22 PMApiDestination
, so I think it's supported by CDKthdxr
04/01/2022, 4:34 PMSeth Geoghegan
04/01/2022, 4:39 PMServerless Patterns▾
Seth Geoghegan
04/01/2022, 4:39 PMSeth Geoghegan
04/01/2022, 4:41 PMFrank
import * as events from "aws-cdk-lib/aws-events";
import * as targets from "aws-cdk-lib/aws-events-targets";
const connection = new events.Connection(this, 'Connection', {
authorization: events.Authorization.apiKey('x-api-key', SecretValue.secretsManager('ApiSecretName')),
description: 'Connection with API Key x-api-key',
});
const destination = new events.ApiDestination(this, 'Destination', {
connection,
endpoint: '<https://example.com>',
description: 'Calling <http://example.com|example.com> with API key x-api-key',
});
const target = new targets.ApiDestination(destination)
And then u can add the target to an existing rule or create a new rule.Seth Geoghegan
04/03/2022, 11:40 PMSeth Geoghegan
04/04/2022, 6:41 PM{
Detail: { "text": "I hope this works" },
DetailType: "my.event.type",
EventBusName: "my_event_bus",
Source: "com.mytest",
}
Into an API request that looks like this:
POST <https://someapi.com/blah>
Authorization: Bearer my-api-token-here
content-type: application/json
{
"text": "I hope this works". // <---this is the request body
}
Seth Geoghegan
04/04/2022, 6:46 PMconst secret = SecretValue.secretsManager("MyApiToken",{jsonField: 'my-token-key'})
const connection = new events.Connection(this, "Connection", {
authorization: events.Authorization.apiKey(
"Authorization",
secret
),
description: "External API connection"
});
const destination = new events.ApiDestination(this, "Destination", {
connection,
endpoint: "<https://webhook.site/blahblahblah>",
httpMethod: <http://events.HttpMethod.POST|events.HttpMethod.POST>,
rateLimitPerSecond: 10,
description: "Calling webhook with API key x-api-key",
});
// this is the Input Transformer configuration I struggled to get working
const apiDestinationProps: targets.ApiDestinationProps = {
event: RuleTargetInput.fromObject({
text: events.EventField.fromPath('$.detail.text')
})
};
const myApiTarget = new targets.ApiDestination(destination, apiDestinationProps);
const rule = new events.Rule(this, "Rule", {
eventBus: bus.eventBridgeEventBus, // bus is an SST EventBus
eventPattern: {
source: ["my_event_bus"],
detailType: ["my.event.type"],
},
targets: [myApiTarget],
});
thdxr
04/04/2022, 6:47 PMthdxr
04/04/2022, 6:47 PMSeth Geoghegan
04/04/2022, 6:51 PM