Skip to content

New serverless pattern - s3-lambda-bedrock-annotations-cdk#3154

Open
NithinChandranR-AWS wants to merge 7 commits into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-s3-lambda-bedrock-annotations-cdk
Open

New serverless pattern - s3-lambda-bedrock-annotations-cdk#3154
NithinChandranR-AWS wants to merge 7 commits into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-s3-lambda-bedrock-annotations-cdk

Conversation

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor

Description

Automated AI document enrichment pipeline using Amazon S3 Annotations (launched June 17, 2026 at AWS Summit NYC) and Amazon Bedrock.

When a file is uploaded to S3, a Lambda function reads the content, invokes Bedrock Claude Sonnet 4 to generate a structured summary, keywords, and content classification, then stores the result as a queryable S3 annotation via PutObjectAnnotation.

Architecture

S3 (Object Created) → Amazon EventBridge → AWS Lambda (Python 3.12 + boto3 layer) → Amazon Bedrock → S3 Annotation

Testing

Deployed and end-to-end tested with .txt, .csv, and .json files. Annotations retrieved successfully via GetObjectAnnotation and ListObjectAnnotations.

Key Implementation Details

  • Requires boto3 >= 1.43.31 (bundled as Lambda layer) for S3 Annotations API support
  • Uses inference profile us.anthropic.claude-sonnet-4-20250514-v1:0 (on-demand model invocation requires inference profiles)
  • Annotation table config not yet CFN-supported; documented as optional CLI step

Checklist

  • CDK synth passes
  • Deployed and tested
  • README with testing instructions
  • example-pattern.json metadata
  • IAM least-privilege
  • Cleanup instructions

…count-level enforcement pattern

Creates a Bedrock Guardrail with content and topic filters, versions
it, and enables account-level enforcement via AwsCustomResource. Test
Lambda demonstrates automatic guardrail enforcement on all Bedrock
calls without specifying guardrailIdentifier.

Key features:
- Account-level guardrail enforcement via PutEnforcedGuardrailConfiguration
- AwsCustomResource for SDK commands not in Lambda runtime
- Content filters (HATE, INSULTS, SEXUAL, VIOLENCE, MISCONDUCT, PROMPT_ATTACK)
- Denied topic filter (investment advice)
- Test Lambda showing safe vs blocked responses
- Automatic cleanup on stack deletion
Replace wildcard resource with specific inference profile ARN and
foundation-model/* for least-privilege IAM.
… to enforcement-cdk

Address bfreiberg review on PR aws-samples#3067:
- Replace both AwsCustomResource workarounds with native resources:
  CfnGuardrailVersion + AWS::Bedrock::EnforcedGuardrailConfiguration.
  This removes the broad bedrock:* IAM on the custom resource.
- Rename folder/stack from bedrock-guardrails-cross-account-cdk to
  bedrock-guardrails-enforcement-cdk (name was misleading; pattern is
  account-level enforcement, not cross-account).
- Add scoped bedrock:ApplyGuardrail to the test Lambda - required when an
  enforced guardrail is active even without passing guardrailIdentifier
  (found via live deploy+test, was failing with AccessDenied).
- Fix test harness: enforced-guardrail interventions return
  stopReason 'guardrail_intervened' in-band, not a thrown exception.
- Bump Lambda runtime to nodejs24.x; example-pattern.json title/description/level.

Deployed, tested, and torn down via CodeBuild in us-east-1:
safe prompt end_turn (allowed), violating prompt guardrail_intervened (blocked),
no guardrailIdentifier passed. tsc clean.

sim: aws-samples#3067
Deploy an automated document enrichment pipeline that generates AI
metadata (summary, keywords, content type) via Amazon Bedrock and
stores it as queryable S3 annotations using the new PutObjectAnnotation
API launched at AWS Summit NYC 2026.

Architecture: S3 Object Created -> EventBridge -> Lambda -> Bedrock
(Claude Sonnet 4) -> PutObjectAnnotation

Tested with .txt, .csv, and .json files on account 742460038667.
- Amazon S3 (not S3), Amazon Bedrock (not Bedrock), AWS Lambda (not Lambda)
- Fix expected output model ID to match actual inference profile
- Apply to README, example-pattern.json, CDK stack comments, handler docstring
- Add try/except error handling on SDK calls in Lambda handler
- Wrap deploy/cleanup commands in <code> tags in example-pattern.json
- Add cdk.context.json to .gitignore
- Remove broken architecture.png reference (file does not exist)
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.

3 participants