diff --git a/eventbridge-query-schedules/snippet-data.json b/eventbridge-query-schedules/snippet-data.json new file mode 100644 index 0000000..d347797 --- /dev/null +++ b/eventbridge-query-schedules/snippet-data.json @@ -0,0 +1,35 @@ +{ + "title": "EventBridge Schedule Finder", + "description": "An interactive CLI command that prompts user inputs to query and find existing EventBridge Scheduler schedules. Supports filtering by schedule name, name prefix, state, group name, and AWS region", + "type": "AWS CLI", + "services": ["eventbridge"], + "tags": [], + "languages": ["bash"], + "introBox": { + "headline": "How it works", + "text": [ + "This interactive CLI script prompts the user for optional inputs like Schedule Name, Prefix, State, Group and Region. It dynamically builds the appropriate AWS CLI command using 'get-schedule' for exact lookups or 'list-schedules' for filtered searches. If no filters are provided, it lists all schedules in the specified region." + ] + }, + "gitHub": { + "template": { + "repoURL": "https://github.com/aws-samples/serverless-snippets/tree/main/eventbridge-query-schedules" + } + }, + "snippets": [ + { + "title": "Copy and paste the snippet into your terminal and enter the optional inputs", + "snippetPath": "snippet.txt", + "language": "bash" + } + ], + "authors": [ + { + "headline": "Presented by Archana V", + "name": "Archana V", + "image": "https://media.licdn.com/dms/image/v2/D5603AQGhkVtEhllFEw/profile-displayphoto-shrink_400_400/B56ZZH3LL6H0Ag-/0/1744962369913?e=1774483200&v=beta&t=wAhvwq-jEIWnyQwDfIkK_-Sq16Z4RvpjWtYmDkc3eg4", + "bio": "Solutions Architect at AWS", + "linkedin": "archanavenkat" + } + ] +} \ No newline at end of file diff --git a/eventbridge-query-schedules/snippet.txt b/eventbridge-query-schedules/snippet.txt new file mode 100644 index 0000000..878e989 --- /dev/null +++ b/eventbridge-query-schedules/snippet.txt @@ -0,0 +1,24 @@ +echo -n "Schedule Name (or Enter to skip): " && read NAME && \ +echo -n "Name Prefix (or Enter to skip): " && read PREFIX && \ +echo -n "State [ENABLED/DISABLED/Enter to skip]: " && read STATE && \ +echo -n "Group Name (or Enter to skip): " && read GROUP && \ +echo -n "Region [us-east-1]: " && read REGION && \ +REGION=${REGION:-us-east-1} && \ +CMD="" && \ +if [ -n "$NAME" ] && [ -z "$STATE" ]; then \ + CMD="aws scheduler get-schedule --name $NAME --region $REGION"; \ + [ -n "$GROUP" ] && CMD="$CMD --group-name $GROUP"; \ + CMD="$CMD --query '{Name:Name,State:State,Expression:ScheduleExpression,Group:GroupName,TargetArn:Target.Arn,Description:Description}' --output table"; \ +elif [ -n "$NAME" ] && [ -n "$STATE" ]; then \ + CMD="aws scheduler list-schedules --region $REGION --name-prefix $NAME --state $STATE"; \ + [ -n "$GROUP" ] && CMD="$CMD --group-name $GROUP"; \ + CMD="$CMD --query 'Schedules[?Name==\`$NAME\`].[Name,State,ScheduleExpression,GroupName,Target.Arn]' --output table"; \ +else \ + CMD="aws scheduler list-schedules --region $REGION"; \ + [ -n "$PREFIX" ] && CMD="$CMD --name-prefix $PREFIX"; \ + [ -n "$STATE" ] && CMD="$CMD --state $STATE"; \ + [ -n "$GROUP" ] && CMD="$CMD --group-name $GROUP"; \ + CMD="$CMD --query 'Schedules[].[Name,State,ScheduleExpression,GroupName,Target.Arn]' --output table"; \ +fi && \ +echo "Running: $CMD" && \ +eval $CMD \ No newline at end of file