Skip to content

feat(lambda-durable-bedrock-async-invoke-cdk) new pattern#2984

Open
bfreiberg wants to merge 4 commits intoaws-samples:mainfrom
bfreiberg:bfreiberg-lambda-durable-bedrock-async-invoke
Open

feat(lambda-durable-bedrock-async-invoke-cdk) new pattern#2984
bfreiberg wants to merge 4 commits intoaws-samples:mainfrom
bfreiberg:bfreiberg-lambda-durable-bedrock-async-invoke

Conversation

@bfreiberg
Copy link
Contributor

Issue #, if available: #2986

Description of changes:
This pattern shows how to use AWS Lambda durable functions to orchestrate Amazon Bedrock Async Invoke for AI video generation. The durable function starts an Amazon Nova Reel video generation job, then polls for completion using waitForCondition with exponential backoff. During each polling interval the function suspends execution entirely, incurring zero compute charges while Bedrock processes the video.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


This pattern shows how to use AWS Lambda durable functions to orchestrate [Amazon Bedrock Async Invoke](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_StartAsyncInvoke.html) for AI video generation. The durable function starts an Amazon Nova Reel video generation job, then polls for completion using `waitForCondition` with exponential backoff. During each polling interval the function suspends execution entirely, incurring zero compute charges while Bedrock processes the video.

Without durable functions this pattern would require a separate polling mechanism such as Step Functions, EventBridge rules, or a cron-based poller. Here the entire workflow is a single, linear function that reads top-to-bottom.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Without durable functions this pattern would require a separate polling mechanism such as Step Functions, EventBridge rules, or a cron-based poller. Here the entire workflow is a single, linear function that reads top-to-bottom.
Without durable functions this pattern would require separate polling mechanism such as in-process waiting (charging for idle time) or additional infrastructure for orchestration or cron schedules. Here the entire workflow is a single, linear function that reads top-to-bottom.


Once the status shows `SUCCEEDED`, the result will contain the S3 URI where the video was written.

### Run unit tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, just saw we have that - should be moved up before deployment

error: error.message,
prompt: event.prompt,
});
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: will fail the execution, if that's what we want (perhaps yes?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right behavior in my opinion because:

  • The error has already exhausted any step-level retries (configured via bedrockRetryStrategy / defaultRetryStrategy)
  • Re-throwing surfaces the failure to the caller via the durable execution status
  • It matches the error handling from our official guidance

…figuration and testing guidance

- Add Configuration section documenting environment variables (BEDROCK_MODEL_ID, BEDROCK_REGION, OUTPUT_BUCKET_NAME)
- Include table with variable defaults and descriptions for clarity
- Move unit test instructions earlier in deployment workflow (before CDK deploy)
- Clarify that tests verify both CDK infrastructure and durable handler functionality
- Update pattern description to better explain polling alternatives and cost benefits
…ons and update paths

- Add log file exclusions to .gitignore (error.log, combined.log)
- Update README documentation links and directory paths to reflect -cdk suffix
- Update example-pattern.json repository and project folder references to -cdk variant
- Refactor IAM policy statements to scope Bedrock permissions to Nova Reel model ARN
- Split GetAsyncInvoke permission into separate policy statement scoped to invocation ARNs
- Update test to verify scoped Bedrock permissions are correctly applied
- Improves security posture by following principle of least privilege for Bedrock access
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants