Skip to content

Commit 982f970

Browse files
jstrunkkrokokomergify[bot]
authored
feat(construct): bedrock batch step functions fragment (#928)
* feat(construct): bedrock batch step functions fragment This PR introduces a new L3 construct BedrockBatchSfn that simplifies running batch inference jobs with Amazon Bedrock using AWS Step Functions. The construct creates a state machine fragment that: - Processes multiple input manifests in parallel using Step Functions Map state - Creates and monitors Bedrock batch inference jobs asynchronously - Handles job completion to continue state machine execution without polling. - Manages IAM roles and permissions for secure execution - Provides configurable timeout settings (24h-168h range) This construct helps developers implement batch inference workflows without managing complex infrastructure code, while following AWS best practices for security and scalability. --------- Co-authored-by: Alain Krok <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent b4bd5bf commit 982f970

33 files changed

+2681
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ The following constructs are available in the library:
139139
| [Amazon Bedrock Monitoring (Amazon CloudWatch Dashboard)](./src/patterns/gen-ai/aws-bedrock-cw-dashboard/README.md) | Amazon CloudWatch dashboard to monitor model usage from Amazon Bedrock. | Amazon CloudWatch |
140140
| [TXT to SQL](./src/patterns/gen-ai/aws-text-to-sql/README.md) | Leverages generative AI capabilities to facilitate natural language-based SQL query generation. | Amazon Event Bridge, Amazon Bedrock, AWS Lambda, Amazon SQS, AWS Secrets, and database of choice |
141141
| [LlamaIndex Data Loading](./src/patterns/gen-ai/aws-llama-index-data-loader/README.md) | Use LlamaIndex to load data in preparation for generative AI workloads | Amazon ECS Fargate, Amazon SQS, and AWS Systems Manager Parameters |
142+
| [Bedrock Batch Step Functions](./src/patterns/gen-ai/aws-bedrock-batch-stepfn/README.md) | Manage Bedrock model invocation jobs(batch inference) in AWS Step Functions state machines | AWS Step Functions, AWS Lambda, AWS EventBridge, Amazon Bedrock, AWS IAM |
142143

143144
### L2 Constructs
144145

apidocs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
- [AossCwDashboard](classes/AossCwDashboard.md)
2424
- [BaseClass](classes/BaseClass.md)
25+
- [BedrockBatchSfn](classes/BedrockBatchSfn.md)
2526
- [BedrockCwDashboard](classes/BedrockCwDashboard.md)
2627
- [ContainerImage](classes/ContainerImage.md)
2728
- [ContentGenerationAppSyncLambda](classes/ContentGenerationAppSyncLambda.md)
@@ -43,6 +44,7 @@
4344
- [AossCwDashboardProps](interfaces/AossCwDashboardProps.md)
4445
- [AsyncInferenceConfig](interfaces/AsyncInferenceConfig.md)
4546
- [BaseClassProps](interfaces/BaseClassProps.md)
47+
- [BedrockBatchSfnProps](interfaces/BedrockBatchSfnProps.md)
4648
- [BedrockCwDashboardProps](interfaces/BedrockCwDashboardProps.md)
4749
- [CollectionMonitoringProps](interfaces/CollectionMonitoringProps.md)
4850
- [ContainerImageConfig](interfaces/ContainerImageConfig.md)

apidocs/classes/BedrockBatchSfn.md

+257
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
[**@cdklabs/generative-ai-cdk-constructs**](../README.md)
2+
3+
***
4+
5+
[@cdklabs/generative-ai-cdk-constructs](../README.md) / BedrockBatchSfn
6+
7+
# Class: BedrockBatchSfn
8+
9+
A state machine fragment that creates a Bedrock Batch Inference Job and waits for its completion.
10+
11+
Input schema:
12+
```
13+
{
14+
"job_name": string, // Required. Name of the batch inference job
15+
"manifest_keys": string[], // Required. List of S3 keys of the input manifest files
16+
"model_id": string // Required. Model ID to use.
17+
}
18+
```
19+
20+
Output schema:
21+
```
22+
{
23+
"status": string, // Required. Status of the batch job. One of: "Completed" or "PartiallyCompleted"
24+
"bucket": string, // Required. S3 bucket where the output is stored
25+
"keys": string[] // Required. Array of S3 keys for the output files
26+
}
27+
```
28+
29+
Error schema:
30+
```
31+
{
32+
"status": string, // Required. Status will be one of: "Failed", "Stopped", or "Expired"
33+
"error": string, // Required. Error code
34+
"cause": string // Required. Error message
35+
}
36+
```
37+
38+
## Extends
39+
40+
- `StateMachineFragment`
41+
42+
## Constructors
43+
44+
### new BedrockBatchSfn()
45+
46+
> **new BedrockBatchSfn**(`parent`, `id`, `props`): [`BedrockBatchSfn`](BedrockBatchSfn.md)
47+
48+
#### Parameters
49+
50+
##### parent
51+
52+
`Construct`
53+
54+
##### id
55+
56+
`string`
57+
58+
##### props
59+
60+
[`BedrockBatchSfnProps`](../interfaces/BedrockBatchSfnProps.md)
61+
62+
#### Returns
63+
64+
[`BedrockBatchSfn`](BedrockBatchSfn.md)
65+
66+
#### Overrides
67+
68+
`sfn.StateMachineFragment.constructor`
69+
70+
## Properties
71+
72+
### endStates
73+
74+
> `readonly` **endStates**: `INextable`[]
75+
76+
The states to chain onto if this fragment is used
77+
78+
#### Overrides
79+
80+
`sfn.StateMachineFragment.endStates`
81+
82+
***
83+
84+
### node
85+
86+
> `readonly` **node**: `Node`
87+
88+
The tree node.
89+
90+
#### Inherited from
91+
92+
`sfn.StateMachineFragment.node`
93+
94+
***
95+
96+
### startState
97+
98+
> `readonly` **startState**: `State`
99+
100+
The start state of this state machine fragment
101+
102+
#### Overrides
103+
104+
`sfn.StateMachineFragment.startState`
105+
106+
## Accessors
107+
108+
### id
109+
110+
#### Get Signature
111+
112+
> **get** **id**(): `string`
113+
114+
Descriptive identifier for this chainable
115+
116+
##### Returns
117+
118+
`string`
119+
120+
#### Inherited from
121+
122+
`sfn.StateMachineFragment.id`
123+
124+
## Methods
125+
126+
### next()
127+
128+
> **next**(`next`): `Chain`
129+
130+
Continue normal execution with the given state
131+
132+
#### Parameters
133+
134+
##### next
135+
136+
`IChainable`
137+
138+
#### Returns
139+
140+
`Chain`
141+
142+
#### Inherited from
143+
144+
`sfn.StateMachineFragment.next`
145+
146+
***
147+
148+
### prefixStates()
149+
150+
> **prefixStates**(`prefix`?): `StateMachineFragment`
151+
152+
Prefix the IDs of all states in this state machine fragment
153+
154+
Use this to avoid multiple copies of the state machine all having the
155+
same state IDs.
156+
157+
#### Parameters
158+
159+
##### prefix?
160+
161+
`string`
162+
163+
The prefix to add. Will use construct ID by default.
164+
165+
#### Returns
166+
167+
`StateMachineFragment`
168+
169+
#### Inherited from
170+
171+
`sfn.StateMachineFragment.prefixStates`
172+
173+
***
174+
175+
### toSingleState()
176+
177+
> **toSingleState**(`options`?): `Parallel`
178+
179+
Wrap all states in this state machine fragment up into a single state.
180+
181+
This can be used to add retry or error handling onto this state
182+
machine fragment.
183+
184+
Be aware that this changes the result of the inner state machine
185+
to be an array with the result of the state machine in it. Adjust
186+
your paths accordingly. For example, change 'outputPath' to
187+
'$[0]'.
188+
189+
#### Parameters
190+
191+
##### options?
192+
193+
`SingleStateOptions`
194+
195+
#### Returns
196+
197+
`Parallel`
198+
199+
#### Inherited from
200+
201+
`sfn.StateMachineFragment.toSingleState`
202+
203+
***
204+
205+
### toString()
206+
207+
> **toString**(): `string`
208+
209+
Returns a string representation of this construct.
210+
211+
#### Returns
212+
213+
`string`
214+
215+
#### Inherited from
216+
217+
`sfn.StateMachineFragment.toString`
218+
219+
***
220+
221+
### isConstruct()
222+
223+
> `static` **isConstruct**(`x`): `x is Construct`
224+
225+
Checks if `x` is a construct.
226+
227+
Use this method instead of `instanceof` to properly detect `Construct`
228+
instances, even when the construct library is symlinked.
229+
230+
Explanation: in JavaScript, multiple copies of the `constructs` library on
231+
disk are seen as independent, completely different libraries. As a
232+
consequence, the class `Construct` in each copy of the `constructs` library
233+
is seen as a different class, and an instance of one class will not test as
234+
`instanceof` the other class. `npm install` will not create installations
235+
like this, but users may manually symlink construct libraries together or
236+
use a monorepo tool: in those cases, multiple copies of the `constructs`
237+
library can be accidentally installed, and `instanceof` will behave
238+
unpredictably. It is safest to avoid using `instanceof`, and using
239+
this type-testing method instead.
240+
241+
#### Parameters
242+
243+
##### x
244+
245+
`any`
246+
247+
Any object
248+
249+
#### Returns
250+
251+
`x is Construct`
252+
253+
true if `x` is an object created from a class which extends `Construct`.
254+
255+
#### Inherited from
256+
257+
`sfn.StateMachineFragment.isConstruct`

0 commit comments

Comments
 (0)