Skip to content

Commit 8619362

Browse files
authored
Merge pull request #2855 from kakakakakku/stepfunctions-bedrock-sam
stepfunctions-bedrock-sam: Update ModelId to Claude Sonnet 4.5
2 parents 5ea72ba + ce5a907 commit 8619362

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

stepfunctions-bedrock-sam/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# AWS Step Functions Express Workflow to Amazon Bedrock Anthropic Claude Model v2.1 for Content Generation
1+
# AWS Step Functions Express Workflow to Amazon Bedrock Anthropic Claude Sonnet 4.5 for Content Generation
22

33
The Step Functions Express Workflow can be started using the AWS CLI or from another service (e.g. API Gateway).
44

5-
The SAM template deploys a Step Functions Express workflow that invokes Amazon Bedrock Anthropic Claude Model v2.1 and returns the generated content based on the provided prompts. The SAM template contains the required resources with IAM permission to run the application with logging enabled.
5+
The SAM template deploys a Step Functions Express workflow that invokes Amazon Bedrock Anthropic Claude Sonnet 4.5 and returns the generated content based on the provided prompts. The SAM template contains the required resources with IAM permission to run the application with logging enabled.
66

77
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/stepfunctions-bedrock-sam
88

@@ -42,7 +42,7 @@ Important: this application uses various AWS services and there are costs associ
4242
## How it works
4343
4444
* Start the Express Workflow using the `start-sync-execution` api command with a "prompt" string in English for generating content as per the input payload.
45-
* The Express Workflow invokes Amazon Bedrock Anthropic Claude v2.1 Model with the prompt.
45+
* The Express Workflow invokes Amazon Bedrock Anthropic Claude Sonnet 4.5 with the prompt.
4646
* Amazon Bedrock returns the generated content as the given promptsentiment of the input text.
4747
* If the integration succeeds, the generated content is returned in the Step Function execution results within an `output` object.
4848
* If the integration fails, the Step Functions workflow will retry up to 5 times before exiting with a `status:FAILED` response.
@@ -57,7 +57,7 @@ Please refer to the architecture diagram below:
5757
Run the following AWS CLI command to send a 'start-sync-execution` command to start the Step Functions workflow. Note, you must edit the {StateMachineExpressSyncToBedrockArn} placeholder with the ARN of the deployed Step Functions workflow. This is provided in the stack outputs. Also, please update {your-region} with the region that you provided while running the SAM template.
5858
5959
```bash
60-
aws stepfunctions start-sync-execution --name "test" --state-machine-arn "{StateMachineExpressSyncToBedrockArn}" --input "{\"prompt\": \"\n\nHuman:Write 5 lines about how Moon was formed.\n\nAssistant:\"}" --region {your-region}
60+
aws stepfunctions start-sync-execution --name "test" --state-machine-arn "{StateMachineExpressSyncToBedrockArn}" --input "{\"prompt\": \"Write 5 lines about how Moon was formed.\"}" --region {your-region}
6161
```
6262

6363
### Example output:
@@ -70,22 +70,22 @@ aws stepfunctions start-sync-execution --name "test" --state-machine-arn "{Stat
7070
"startDate": "2024-01-08T11:49:18.981000+05:30",
7171
"stopDate": "2024-01-08T11:49:28.758000+05:30",
7272
"status": "SUCCEEDED",
73-
"input": "{\"prompt\": \"\\n\\nHuman:Write 5 lines about how Moon was formed.\\n\\nAssistant:\"}",
73+
"input": "{\"prompt\": \"Write 5 lines about how Moon was formed.\"}",
7474
"inputDetails": {
7575
"included": true
7676
},
77-
"output": "{\"Body\":{\"completion\":\" Here is a 5 line summary of how the Moon was formed:\\n\\n1. The leading theory is that the Moon formed from debris left over after a massive collision between the young Earth and a Mars-sized body about 4.5 billion years ago.\\n\\n2. This collision threw molten rock and debris into Earth's orbit that eventually cooled and coalesced into the Moon we see today. \\n\\n3. Over billions of years, the Moon's gravity caused Earth's rotation to slow down and its orbit to expand outward. \\n\\n4. The Moon likely had an intense period of volcanism in its early history, but volcanism ended around 3 billion years ago as the Moon's interior cooled.\\n\\n5. Without the stabilizing effect of the Moon, Earth would wobble more on its axis, causing more radical climate swings over long time periods.\",\"stop_reason\":\"stop_sequence\",\"stop\":\"\\n\\nHuman:\"},\"ContentType\":\"application/json\"}",
77+
"output": "{\"Body\":{\"model\":\"claude-sonnet-4-5-20250929\",\"id\":\"msg_bdrk_014iQLvHi98ir4DN9aaqNs1P\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"# How the Moon Was Formed\\n\\n1. **Giant Impact**: About 4.5 billion years ago, a Mars-sized object called Theia collided with the early Earth in a catastrophic impact.\\n\\n2. **Debris Field**: The collision ejected massive amounts of rocky debris from both Earth and Theia into orbit around our planet.\\n\\n3. **Accretion Process**: This orbiting debris gradually clumped together through gravitational attraction over millions of years.\\n\\n4. **Moon Formation**: The accumulated material eventually coalesced to form the Moon, which initially orbited much closer to Earth than it does today.\\n\\n5. **Supporting Evidence**: This \\\"Giant Impact Hypothesis\\\" is supported by the Moon's composition being similar to Earth's mantle and its relatively small iron core.\"}],\"stop_reason\":\"end_turn\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":18,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"output_tokens\":173}},\"ContentType\":\"application/json\"}",
7878
"outputDetails": {
7979
"included": true
8080
},
8181
"billingDetails": {
8282
"billedMemoryUsedInMB": 64,
83-
"billedDurationInMilliseconds": 9800
83+
"billedDurationInMilliseconds": 4900
8484
}
8585
}
8686
```
8787
## Cleanup
88-
88+
8989
Delete the stack
9090
```bash
9191
sam delete

stepfunctions-bedrock-sam/example-pattern.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"title": "AWS Step Functions to Amazon Bedrock Integration",
3-
"description": "The SAM template deploys a Step Functions workflow that invokes Amazon Bedrock Anthropic Claude Model v2.1 to generate content for a given prompt.",
3+
"description": "The SAM template deploys a Step Functions workflow that invokes Amazon Bedrock Anthropic Claude Sonnet 4.5 to generate content for a given prompt.",
44
"language": "YAML",
55
"level": "200",
66
"framework": "AWS SAM",
77
"introBox": {
88
"headline": "How it works",
99
"text": [
1010
"Start the Express Workflow using the `start-sync-execution` api command with a prompt string in English for generating content as per the input payload.",
11-
"The Express Workflow invokes Amazon Bedrock Anthropic Claude v2.1 Model with the prompt.",
11+
"The Express Workflow invokes Amazon Bedrock Anthropic Claude Sonnet 4.5 with the prompt.",
1212
"Amazon Bedrock returns the generated content as the given promptsentiment of the input text.",
1313
"If the integration works fine, the generated content is returned in Step Function execution results within a output object.",
1414
"If the integration fails, the Step Functions workflow will retry up to 5 times before exiting with a status:FAILED response."

stepfunctions-bedrock-sam/sfn-bedrock-sam.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"title": "AWS Step Functions to Amazon Bedrock Integration",
3-
"description": "This SAM template deploys a Step Functions workflow that invokes Amazon Bedrock Anthropic Claude Model v2.1 to generate content for a given prompt.",
3+
"description": "This SAM template deploys a Step Functions workflow that invokes Amazon Bedrock Anthropic Claude Sonnet 4.5 to generate content for a given prompt.",
44
"language": "YAML",
55
"level": "200",
66
"framework": "AWS SAM",
77
"introBox": {
88
"headline": "How it works",
99
"text": [
1010
"Start the Express Workflow using the `start-sync-execution` api command with a prompt string in English for generating content as per the input payload.",
11-
"The Express Workflow invokes Amazon Bedrock Anthropic Claude v2.1 Model with the prompt.",
11+
"The Express Workflow invokes Amazon Bedrock Anthropic Claude Sonnet 4.5 with the prompt.",
1212
"Amazon Bedrock returns the generated content as the given promptsentiment of the input text.",
1313
"If the integration succeeds, the generated content is returned in Step Function execution results within an output object.",
1414
"If the integration fails, the Step Functions workflow will retry up to 5 times before exiting with a status:FAILED response."

stepfunctions-bedrock-sam/statemachine/bedrock-integration.asl.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Comment": "This state machine demonstrates the integration with Amazon Bedrock Anthropic Claude v2.1 Model",
2+
"Comment": "This state machine demonstrates the integration with Amazon Bedrock Anthropic Claude Sonnet 4.5",
33
"StartAt": "Bedrock InvokeModel",
44
"States": {
55
"Bedrock InvokeModel": {
@@ -8,8 +8,19 @@
88
"Parameters": {
99
"ModelId": "${ModelId}",
1010
"Body": {
11-
"prompt.$": "$.prompt",
12-
"max_tokens_to_sample": 200
11+
"anthropic_version": "bedrock-2023-05-31",
12+
"messages": [
13+
{
14+
"role": "user",
15+
"content": [
16+
{
17+
"type": "text",
18+
"text.$": "$.prompt"
19+
}
20+
]
21+
}
22+
],
23+
"max_tokens": 200
1324
}
1425
},
1526
"Retry": [
@@ -25,4 +36,4 @@
2536
"End": true
2637
}
2738
}
28-
}
39+
}

stepfunctions-bedrock-sam/template.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Resources:
1414
Properties:
1515
DefinitionUri: statemachine/bedrock-integration.asl.json
1616
DefinitionSubstitutions:
17-
ModelId: !Sub arn:aws:bedrock:${AWS::Region}::foundation-model/anthropic.claude-v2:1
17+
ModelId: !Sub arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:inference-profile/global.anthropic.claude-sonnet-4-5-20250929-v1:0
1818
Role:
1919
Fn::GetAtt: [ StatesExecutionRole, Arn ]
2020
Type: EXPRESS
@@ -32,7 +32,7 @@ Resources:
3232
Type: AWS::Logs::LogGroup
3333
Properties:
3434
LogGroupName: !Join [ "/", [ "stepfunctions", StateMachineExpressSyncToBedrock]]
35-
35+
3636
##########################################################################
3737
# Roles #
3838
##########################################################################
@@ -72,8 +72,10 @@ Resources:
7272
Statement:
7373
- Effect: Allow
7474
Action:
75-
- "bedrock:InvokeModel"
76-
Resource: !Sub arn:aws:bedrock:${AWS::Region}::foundation-model/anthropic.claude-v2:1
75+
- "bedrock:InvokeModel*"
76+
Resource:
77+
- !Sub arn:aws:bedrock:*:*:inference-profile/global.anthropic.claude-sonnet-4-5-20250929-v1:0
78+
- !Sub arn:aws:bedrock:*::foundation-model/anthropic.claude-sonnet-4-5-20250929-v1:0
7779
##########################################################################
7880
# Outputs #
7981
##########################################################################

0 commit comments

Comments
 (0)