Skip to content

Commit 95b2303

Browse files
jckdotimclaude
andcommitted
fix: set EventBridge schedule to 5 minutes to match Lambda timeout
Lambda timeout is 300s (5 min). Running at 1 min intervals would cause concurrent executions overlapping — set schedule to rate(5 minutes) to ensure each invocation completes before the next one starts. bootstrap-dynamodb.sh now also configures: - EventBridge rule (rate(5 minutes)) - Lambda permission for EventBridge invocation - Lambda timeout enforcement (300s) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1f398a4 commit 95b2303

1 file changed

Lines changed: 64 additions & 2 deletions

File tree

infra/bootstrap-dynamodb.sh

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#!/bin/bash
2-
# Creates bridge-monitor-state and bridge-exchange-histories DynamoDB tables
3-
# Usage: AWS_REGION=us-east-1 bash bootstrap-dynamodb.sh
2+
# Creates bridge-monitor-state and bridge-exchange-histories DynamoDB tables,
3+
# and sets up the EventBridge rule to trigger the Lambda every 5 minutes.
4+
#
5+
# Lambda timeout must be set to 5 minutes (300s) to match the schedule interval.
6+
# EventBridge fires every 5 minutes — Lambda must finish before the next invocation.
7+
#
8+
# Usage:
9+
# AWS_REGION=us-east-1 LAMBDA_FUNCTION_NAME=bridge-relayer bash bootstrap-dynamodb.sh
410

511
set -e
612

713
REGION="${AWS_REGION:-us-east-1}"
14+
LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME:-bridge-relayer}"
15+
SCHEDULE_EXPRESSION="rate(5 minutes)" # Must match Lambda timeout (300s)
816

917
echo "Creating DynamoDB tables in region: ${REGION}"
1018

@@ -55,3 +63,57 @@ echo "bridge-exchange-histories created."
5563

5664
echo ""
5765
echo "All DynamoDB tables created successfully."
66+
67+
# --- EventBridge rule: invoke Lambda every 5 minutes ---
68+
echo ""
69+
echo "Setting up EventBridge schedule (${SCHEDULE_EXPRESSION})..."
70+
71+
RULE_NAME="bridge-relayer-schedule"
72+
73+
RULE_ARN=$(aws events put-rule \
74+
--region "$REGION" \
75+
--name "$RULE_NAME" \
76+
--schedule-expression "$SCHEDULE_EXPRESSION" \
77+
--state ENABLED \
78+
--description "Triggers bridge-relayer Lambda every 5 minutes" \
79+
--query 'RuleArn' \
80+
--output text)
81+
82+
echo "EventBridge rule created: ${RULE_ARN}"
83+
84+
LAMBDA_ARN=$(aws lambda get-function \
85+
--region "$REGION" \
86+
--function-name "$LAMBDA_FUNCTION_NAME" \
87+
--query 'Configuration.FunctionArn' \
88+
--output text)
89+
90+
# Allow EventBridge to invoke the Lambda
91+
aws lambda add-permission \
92+
--region "$REGION" \
93+
--function-name "$LAMBDA_FUNCTION_NAME" \
94+
--statement-id "AllowEventBridgeInvoke" \
95+
--action "lambda:InvokeFunction" \
96+
--principal "events.amazonaws.com" \
97+
--source-arn "$RULE_ARN" \
98+
2>/dev/null || echo " (permission already exists, skipping)"
99+
100+
aws events put-targets \
101+
--region "$REGION" \
102+
--rule "$RULE_NAME" \
103+
--targets "Id=bridge-relayer-target,Arn=${LAMBDA_ARN}"
104+
105+
echo "EventBridge rule wired to Lambda: ${LAMBDA_FUNCTION_NAME}"
106+
107+
# --- Lambda timeout: enforce 300s (5 minutes) ---
108+
echo ""
109+
echo "Setting Lambda timeout to 300s..."
110+
aws lambda update-function-configuration \
111+
--region "$REGION" \
112+
--function-name "$LAMBDA_FUNCTION_NAME" \
113+
--timeout 300
114+
115+
echo ""
116+
echo "Bootstrap complete."
117+
echo " Schedule : ${SCHEDULE_EXPRESSION}"
118+
echo " Lambda : ${LAMBDA_FUNCTION_NAME} (timeout: 300s)"
119+
echo " Tables : bridge-monitor-state, bridge-exchange-histories"

0 commit comments

Comments
 (0)