[{"data":1,"prerenderedAt":105},["ShallowReactive",2],{"pattern-bedrock-prompt-management-lambda-python-sam":3,"pattern-group-bedrock-prompt-management-lambda-python-sam":79},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":13,"deploy":15,"description":19,"extension":20,"framework":21,"gitHub":22,"highlight":6,"introBox":26,"language":34,"level":35,"meta":36,"patternArch":37,"patternGroup":51,"patternGroupLabel":6,"resources":52,"stem":73,"testing":74,"videoId":6,"__hash__":78},"patterns\u002Fpatterns\u002Fbedrock-prompt-management-lambda-python-sam.json","Version generative AI prompts with Amazon Bedrock Prompt Management",null,{"headline":8,"text":9},"Cleanup",[10,11,12],"1. Delete the stack with AWS SAM, which also deletes the prompt and every version published from it, including the versions published during testing: \u003Ccode>sam delete --stack-name STACK_NAME --region REGION\u003C\u002Fcode>. Enter \u003Ccode>y\u003C\u002Fcode> at each confirmation prompt.","2. Confirm the stack has been deleted: \u003Ccode>aws cloudformation list-stacks --region REGION --query \"StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus\"\u003C\u002Fcode>.","3. Delete the local files created during testing: \u003Ccode>rm -f event.json out.json out2.json out3.json\u003C\u002Fcode>. The Amazon S3 bucket the AWS SAM CLI manages for deployment artifacts is shared by every AWS SAM deployment in that account and Region, so it is not removed.",[14],"content\u002Fcontributors\u002Fmanish-s.json",{"text":16},[17,18],"sam build","sam deploy --guided","Define an Amazon Bedrock managed prompt and a published version in AWS CloudFormation and invoke it from AWS Lambda through Converse.","json","AWS SAM",{"template":23},{"patternPath":24,"templateFile":25},"bedrock-prompt-management-lambda\u002Fpython\u002Fsam","template.yaml",{"headline":27,"text":28},"How it works",[29,30,31,32,33],"Teams building on Amazon Bedrock often hardcode prompt text inside their application code. Changing a prompt then means a code change and a redeploy, and there is no built-in versioning or rollback. Amazon Bedrock Prompt Management solves this by storing prompts as managed, versioned resources, and this pattern shows how to define and invoke them entirely as infrastructure as code.","The pattern defines two native AWS CloudFormation resources: an AWS::Bedrock::Prompt (the prompt template, its input variables, the target model, and inference settings) and an AWS::Bedrock::PromptVersion (an immutable published version of that prompt). Because the prompt lives in Amazon Bedrock rather than in the function, prompt authors can iterate on wording independently of the application code.","At runtime, an AWS Lambda function calls the Amazon Bedrock Converse API and passes the prompt version ARN as the modelId, along with promptVariables for the template placeholders. Converse recognizes the ARN, renders the managed prompt with those values, and runs it against the model configured on the prompt variant, returning the result. The function contains no prompt text at all, only the version ARN it was given.","To change the prompt, you publish a new version in Amazon Bedrock and repoint the function to that version ARN (a configuration value, not code). Rolling back is just pointing at an older version. Invoking a pinned, immutable version keeps production behavior deterministic while still allowing safe iteration, the same idea as feature flags applied to generative AI prompts.","IAM permissions follow least privilege: the function may call bedrock:RenderPrompt, the action Converse checks for a prompt resource, only on this prompt and its versions, plus bedrock:InvokeModel on the model the prompt variant targets. The target model is a template parameter, so the same pattern works with any Converse-compatible Amazon Bedrock model or cross-Region inference profile. Good use cases include support and FAQ assistants, summarization and classification, and any workload where prompts must be iterated, versioned, or rolled back without redeploying application code.","Python","200",{},{"icon1":38,"icon2":43,"line1":47},{"x":39,"y":40,"service":41,"label":42},30,50,"lambda-event-functions","AWS Lambda ",{"x":44,"y":40,"service":45,"label":46},70,"bedrock","Bedrock managed prompt + version",{"from":48,"to":49,"label":50},"icon1","icon2","Converse API","bedrock-prompt-management-lambda",{"headline":53,"bullets":54},"Additional resources",[55,58,61,64,67,70],{"text":56,"link":57},"Prompt management in Amazon Bedrock - documentation","https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fprompt-management.html",{"text":59,"link":60},"Prerequisites for prompt management - IAM permissions","https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fprompt-management-prereq.html",{"text":62,"link":63},"AWS::Bedrock::Prompt - AWS CloudFormation resource","https:\u002F\u002Fdocs.aws.amazon.com\u002FAWSCloudFormation\u002Flatest\u002FUserGuide\u002Faws-resource-bedrock-prompt.html",{"text":65,"link":66},"AWS::Bedrock::PromptVersion - AWS CloudFormation resource","https:\u002F\u002Fdocs.aws.amazon.com\u002FAWSCloudFormation\u002Flatest\u002FUserGuide\u002Faws-resource-bedrock-promptversion.html",{"text":68,"link":69},"Amazon Bedrock Converse API reference","https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002FAPIReference\u002FAPI_runtime_Converse.html",{"text":71,"link":72},"Request access to Amazon Bedrock models","https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fmodel-access.html","patterns\u002Fbedrock-prompt-management-lambda-python-sam",{"headline":75,"text":76},"Testing",[77],"Invoke the AWS Lambda function to run the managed prompt with \u003Ccode>aws lambda invoke --region REGION --function-name FUNCTION_NAME --cli-binary-format raw-in-base64-out --payload file:\u002F\u002Fevent.json out.json\u003C\u002Fcode>, then edit the prompt, publish a new version, and repoint the function to see the output change with no code change. Pass \u003Ccode>--region\u003C\u002Fcode> on every command so that the Region matches the one you deployed to. See the README for detailed instructions.","HV79fx-QQTgKPfJkpXYMWYCUVbV4T4ikTyJ5TSjv_8Q",[80],{"id":4,"title":5,"architectureURL":6,"cleanup":81,"contributors":83,"deploy":84,"description":19,"extension":20,"framework":21,"gitHub":86,"highlight":6,"introBox":88,"language":34,"level":35,"meta":90,"patternArch":91,"patternGroup":51,"patternGroupLabel":6,"resources":95,"stem":73,"testing":103,"videoId":6,"__hash__":78},{"headline":8,"text":82},[10,11,12],[14],{"text":85},[17,18],{"template":87},{"patternPath":24,"templateFile":25},{"headline":27,"text":89},[29,30,31,32,33],{},{"icon1":92,"icon2":93,"line1":94},{"x":39,"y":40,"service":41,"label":42},{"x":44,"y":40,"service":45,"label":46},{"from":48,"to":49,"label":50},{"headline":53,"bullets":96},[97,98,99,100,101,102],{"text":56,"link":57},{"text":59,"link":60},{"text":62,"link":63},{"text":65,"link":66},{"text":68,"link":69},{"text":71,"link":72},{"headline":75,"text":104},[77],1792492480841]