AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-04-20 · Documentation low

File: code-library/latest/ug/python_3_bedrock-agent_code_examples.md

Summary

Added documentation for new Amazon Bedrock Flow management operations including CreateFlow, CreateFlowAlias, CreateFlowVersion, DeleteFlow, DeleteFlowAlias, DeleteFlowVersion, GetFlow, GetFlowVersion, ListFlowAliases, ListFlowVersions, ListFlows, PrepareFlow, UpdateFlow, and UpdateFlowAlias. Modified existing agent-related examples to flow-related operations and added a scenario demonstrating flow creation/execution lifecycle.

Security assessment

Changes focus on adding general feature documentation for flow management operations. While IAM roles are mentioned (security best practice), there's no evidence of addressing vulnerabilities or introducing new security features. The 'skipResourceInUseCheck' parameter in DeleteFlow could impact resource management but isn't explicitly security-related.

Diff

diff --git a/code-library/latest/ug/python_3_bedrock-agent_code_examples.md b/code-library/latest/ug/python_3_bedrock-agent_code_examples.md
index a98c77869..065dcbeb4 100644
--- a//code-library/latest/ug/python_3_bedrock-agent_code_examples.md
+++ b//code-library/latest/ug/python_3_bedrock-agent_code_examples.md
@@ -166,0 +167,167 @@ Create an agent alias.
+The following code example shows how to use `CreateFlow`.
+
+**SDK for Python (Boto3)**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-agent#code-examples). 
+
+Create an Amazon Bedrock flow.
+    
+    
+    def create_flow(client, flow_name, flow_description, role_arn, flow_def):
+        """
+        Creates an Amazon Bedrock flow.
+    
+        Args:
+        client: Amazon Bedrock agent boto3 client.
+        flow_name (str): The name for the new flow.
+        role_arn (str):  The ARN for the IAM role that use flow uses.
+        flow_def (json): The JSON definition of the flow that you want to create.
+    
+        Returns:
+            dict: The response from CreateFlow.
+        """
+        try:
+    
+            logger.info("Creating flow: %s.", flow_name)
+    
+            response = client.create_flow(
+                name=flow_name,
+                description=flow_description,
+                executionRoleArn=role_arn,
+                definition=flow_def
+            )
+    
+            logger.info("Successfully created flow: %s. ID: %s",
+                        flow_name,
+                        {response['id']})
+    
+            return response
+    
+        except ClientError as e:
+            logger.exception("Client error creating flow: %s", {str(e)})
+            raise
+    
+        except Exception as e:
+            logger.exception("Unexepcted error creating flow: %s", {str(e)})
+            raise
+    
+    
+
+  * For API details, see [CreateFlow](https://docs.aws.amazon.com/goto/boto3/bedrock-agent-2023-12-12/CreateFlow) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+
+The following code example shows how to use `CreateFlowAlias`.
+
+**SDK for Python (Boto3)**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-agent#code-examples). 
+
+Create an alias for an Amazon Bedrock flow.
+    
+    
+    def create_flow_alias(client, flow_id, flow_version, name, description):
+        """
+        Creates an alias for an Amazon Bedrock flow.
+    
+        Args:
+            client: bedrock agent boto3 client.
+            flow_id (str): The identifier of the flow.
+    
+        Returns:
+            str: The ID for the flow alias.
+        """
+    
+        try:
+            logger.info("Creating flow alias for flow: %s.", flow_id)
+    
+            response = client.create_flow_alias(
+                flowIdentifier=flow_id,
+                name=name,
+                description=description,
+                routingConfiguration=[
+                    {
+                        "flowVersion": flow_version
+                    }
+                ]
+            )
+            logger.info("Successfully created flow alias for %s.", flow_id)
+    
+            return response['id']
+    
+        except ClientError as e:
+            logging.exception("Client error creating alias for flow: %s - %s",
+                    flow_id, str(e))
+            raise
+        except Exception as e:
+            logging.exception("Unexpected error creating alias for flow : %s - %s",
+                    flow_id, str(e))
+            raise
+    
+    
+
+  * For API details, see [CreateFlowAlias](https://docs.aws.amazon.com/goto/boto3/bedrock-agent-2023-12-12/CreateFlowAlias) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+
+The following code example shows how to use `CreateFlowVersion`.
+
+**SDK for Python (Boto3)**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-agent#code-examples). 
+
+Create a version of an Amazon Bedrock flow.
+    
+    
+    def create_flow_version(client, flow_id, description):
+        """
+        Creates a version of an Amazon Bedrock flow.
+    
+        Args:
+            client: Amazon Bedrock agent boto3 client.
+            flow_id (str): The identifier of the flow.
+            description (str) : A description for the flow.
+    
+        Returns:
+            str: The version for the flow.
+        """
+        try:
+    
+            logger.info("Creating flow version for flow: %s.", flow_id)
+    
+            # Call CreateFlowVersion operation
+            response = client.create_flow_version(
+                flowIdentifier=flow_id,
+                description=description
+            )
+    
+            logging.info("Successfully created flow version %s for flow %s.",
+                response['version'], flow_id)
+            
+            return response['version']
+    
+        except ClientError as e:
+            logging.exception("Client error creating flow: %s", str(e))
+            raise
+        except Exception as e:
+            logging.exception("Unexpected error creating flow : %s", str(e))
+            raise
+    
+    
+
+  * For API details, see [CreateFlowVersion](https://docs.aws.amazon.com/goto/boto3/bedrock-agent-2023-12-12/CreateFlowVersion) in _AWS SDK for Python (Boto3) API Reference_. 
+
+
+
+
@@ -244 +411 @@ Delete an agent alias.
-The following code example shows how to use `GetAgent`.
+The following code example shows how to use `DeleteFlow`.
@@ -253 +420 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-Get an agent.
+Delete an Amazon Bedrock flow.
@@ -256 +423 @@ Get an agent.
-        def get_agent(self, agent_id, log_error=True):
+    def delete_flow(client, flow_id):
@@ -258 +425 @@ Get an agent.
-            Gets information about an agent.
+        Deletes an Amazon Bedrock flow.
@@ -260,6 +427,3 @@ Get an agent.
-            :param agent_id: The unique identifier of the agent.
-            :param log_error: Whether to log any errors that occur when getting the agent.
-                              If True, errors will be logged to the logger. If False, errors
-                              will still be raised, but not logged.
-            :return: The information about the requested agent.
-            """
+        Args:
+        client: Amazon Bedrock agent boto3 client.
+        flow_id (str): The identifier of the flow that you want to delete.
@@ -266,0 +431,3 @@ Get an agent.
+        Returns:
+            dict: The response from the DeleteFLow operation.
+        """
@@ -268,2 +435,14 @@ Get an agent.
-                response = self.client.get_agent(agentId=agent_id)