Skip to content

Instantly share code, notes, and snippets.

@jonny-rimek
Created June 21, 2021 22:22
Show Gist options
  • Save jonny-rimek/6d2862c2a2dae86982e34cffa354038a to your computer and use it in GitHub Desktop.
Save jonny-rimek/6d2862c2a2dae86982e34cffa354038a to your computer and use it in GitHub Desktop.
eventbridge api destination
const bus = new events.EventBus(this, "Bus")
const connection = new events.CfnConnection(this, "BusConnection", {
authorizationType: "API_KEY",
authParameters: {
ApiKeyAuthParameters: {
ApiKeyName: "key_name",
ApiKeyValue: "f8ad5770-6f20-42a7-8614-3b89ed5150aa",
},
},
})
const apiDestination = new events.CfnApiDestination(this, "ApiDestination", {
connectionArn: connection.attrArn,
httpMethod: "GET",
// httpMethod: "POST",
invocationRateLimitPerSecond: 1,
invocationEndpoint: "https://api.wowmate.io/combatlogs/keys",
// invocationEndpoint: "https://api.eu.opsgenie.com",
})
const role = new iam.Role(this, "EventBridgeApiDestinationRole", {
assumedBy: new iam.ServicePrincipal("events.amazonaws.com"),
})
new events.CfnRule(this, "ApiDestinationRule", {
eventPattern: {
source: [{ prefix: "" }],
},
eventBusName: bus.eventBusName,
state: "ENABLED",
targets: [
{
id: "opsgenie-alert-target",
roleArn: role.roleArn,
arn: apiDestination.attrArn,
inputTransformer: {
inputPathsMap: { detail: "$.detail" },
inputTemplate: '{"message":"hi"}',
},
},
],
})
role.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ["events:InvokeApiDestination"],
resources: ["*"],
// resources: [apiDestination.attrArn],
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment