- Newest
- Most votes
- Most comments
Hello there,
I was able to successfully deploy an AgentCore Runtime using the exact same approach you described. Your CDK code structure looks correct and should work.
However, I was able to reproduce the same "Internal error occurred in the handler" error you're experiencing by introducing invalid Python syntax in my “main.py “file:
This caused the same HandlerInternalFailure
def handler(event, context # <-- Missing closing parenthesis invalid_syntax_here!!! return { 'statusCode': 200, 'body': json.dumps('Hello from AgentCore Runtime') }
When I deployed this broken code, I got the identical error:
Resource handler returned message: "Internal error occurred in the handler." (RequestToken: 000, HandlerErrorCode: HandlerInternalFailure)
After fixing the Python syntax errors, the deployment succeeded without issues.
Recommendation: Check your Python code for syntax errors, missing imports, or runtime issues. The BedrockAgentCore service validates your code during deployment, and any Python syntax errors will cause this internal handler failure.
Common issues to check:
-
Missing closing parentheses/brackets
-
Invalid Python syntax
-
Missing required imports
-
Runtime exceptions in your handler code
Validate your Python code - Run “ python -m py_compile main.py “ locally to check for syntax errors
Test your handler function - Ensure it can be imported and executed without errors
Check your entry point - Verify entryPoint: ['main.py'] matches your actual file structure
If you continue experiencing issues after validating your Python code, please open a support case where we will have more visibility and will be able to assist you better.
The issue you're experiencing with the HandlerInternalFailure when deploying your AgentCore Runtime is likely related to how you're providing the code artifact to the CfnRuntime resource.
For Amazon Bedrock AgentCore Runtime direct code deployment, there are a few key requirements and limitations to consider:
-
The code deployment package should be a zip file containing your Python code and dependencies.
-
When specifying the S3 location in the
agentRuntimeArtifact.codeConfiguration.code.s3property, you need to provide:
bucket: The S3 bucket namekey: The name of the zip file (not prefix)
In your current implementation, you're using prefix: runtimeCodeAsset.s3ObjectKey which might be causing the issue. The AgentCore Runtime expects a key pointing directly to a zip file, not a prefix.
Also, there's a size limitation to consider. While the exact limit for AgentCore Runtime isn't explicitly stated in the provided information, deployment packages for similar serverless services typically have size constraints (for example, Lambda has a 250 MB unzipped size limit).
Try modifying your code to ensure the asset is properly zipped and referenced correctly:
const runtimeCodeAsset = new s3assets.Asset(this, 'AgentRuntimeAsset', { path: path.join(__dirname, '../agent'), bundling: { image: DockerImage.fromRegistry('python:3.11-slim'), command: [ 'bash', '-c', [ 'pip install -r requirements.txt -t /tmp/python', 'cp -r . /tmp/python', 'cd /tmp/python', 'zip -r /asset-output/deployment.zip .' ].join(' && '), ], }, }); // Then in your CfnRuntime configuration: agentRuntimeArtifact: { codeConfiguration: { code: { s3: { bucket: runtimeCodeAsset.bucket.bucketName, key: runtimeCodeAsset.s3ObjectKey, }, }, runtime: 'PYTHON_3_11', entryPoint: ['main.py'], }, },
This approach should create a proper zip file containing your code and dependencies, which is what AgentCore Runtime expects for direct code deployment.
If you continue to experience issues, you might want to try the manual approach first (uploading the zip to S3 and referencing it) to confirm that your code package works correctly with AgentCore Runtime before integrating it into your CDK stack.
Sources
Iterate faster with Amazon Bedrock AgentCore Runtime direct code deployment | Artificial Intelligence
Get started with Amazon Bedrock AgentCore Runtime direct code deployment - Amazon Bedrock AgentCore
Unzipped size must be smaller than 262144000 bytes | AWS re:Post
answered a year ago
I think this bot response might misunderstand CDK’s default bundling behavior. The default bundling.outputType is BundlingOutput.AUTO_DISCOVER. That means: if /asset-output contains a single .zip or .jar file, CDK uploads that archive as-is; otherwise, it zips the contents of /asset-output itself and uploads that zip. In other words, you don’t have to create a zip inside /asset-output unless you specifically want to control the archive layout.
Also, the AgentCore docs for direct code deployment (Step 5, “Custom zip + boto3”) show the s3 shape using a prefix that includes the full path and filename (e.g. "{agent_name}/deployment_package.zip"), not a key field. So the prefix vs key distinction in this answer doesn’t match the public AgentCore documentation.
I have to give the bot 3/10 stars for this response, and it only deserves that because one of the references was useful. I still have not resolved the issue.
Relevant content
asked 5 years ago
- AWS OFFICIALUpdated 2 months ago

Thanks, that helped a lot. I had multiple things wrong. The worst of them was not deploying a cpython with a version that matched the runtime version - that causes it to just immediately bomb out.