Created
March 13, 2020 14:27
-
-
Save allenmichael/c5409f9d9eb2b489ce380f1b053c51b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) | |
EVENT_SOURCE_NAME=$(aws events list-event-sources --query 'EventSources[?CreatedBy == `aws.partner/auth0.com`]|[0].Name' --output text) | |
RULE_NAME=auth0 | |
FUNCTION_NAME=Auth0Logs | |
aws events create-event-bus --name $EVENT_SOURCE_NAME --event-source-name $EVENT_SOURCE_NAME | |
EVENT_PATTERN=$(jq -r .EventPattern event-pattern.json | jq --arg ACCOUNT "$ACCOUNT_ID" '.account = $ACCOUNT' | jq 'tostring') | |
jq --arg SOURCE "$EVENT_SOURCE_NAME" --arg NAME "$RULE_NAME" --arg PATTERN "$EVENT_PATTERN" '. + {EventBusName: $SOURCE, Name: $NAME, EventPattern: $PATTERN}' event-pattern.json > event-patten-edited.json | |
aws events put-rule --cli-input-json file://event-pattern-edited.json | |
TARGET_ARN=$(aws lambda list-functions --query "Functions[?FunctionName == '$FUNCTION_NAME']|[0].FunctionArn" --output text) | |
aws events put-targets --rule $RULE_NAME --targets "Id"="1","Arn"=$TARGET_ARN --event-bus-name $EVENT_SOURCE_NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"EventPattern": "{\"account\": [\"$ACCOUNT_ID\"]}", | |
"Name": "$NAME", | |
"EventBusName": "$EVENT_SOURCE_NAME" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment