Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'requestBody' : File "/var/task/lambda_function.py", line 15, in get_named_property event['requestBody']['content']['application/json']['properties'] #226

Open
sabeelms opened this issue Jul 10, 2024 · 1 comment

Comments

@sabeelms
Copy link

sabeelms commented Jul 10, 2024

Hi,

I'm testing "create an action group" for a bedrock agent that can call a lambda function. Creating this action group calls for having an OpenAPI schema which defines the function endpoints, required arguments, and the returns.

However, I'm seeing the following error

LAMBDA_WARNING: Unhandled exception. The most likely cause is an issue in the function code. However, in rare cases, a Lambda runtime update can cause unexpected function behavior. For functions using managed runtimes, runtime updates can be triggered by a function change, or can be applied automatically. To determine if the runtime has been updated, check the runtime version in the INIT_START log entry. If this error correlates with a change in the runtime version, you may be able to mitigate this error by temporarily rolling back to the previous runtime version. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html

[ERROR] KeyError: 'requestBody'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 97, in lambda_handler
    internal_id = get_named_property(event, "internalId")
  File "/var/task/lambda_function.py", line 15, in get_named_property
    event['requestBody']['content']['application/json']['properties']

Can someone please look into this?

@mttanke
Copy link
Contributor

mttanke commented Jul 23, 2024

is internalId defined as a POST or a GET parameter in your OpenAPI schema? you should use get_parameter for GET parameters and get_named_property for POST ones. See readme: https://github.com/aws-samples/amazon-bedrock-samples/tree/main/agents-for-bedrock/features-examples/02-create-agent-with-api-schema

    # getting parameters according to the http method
    if http_method == "get":
        claim_id = get_named_parameter(event, "claim_id")
    elif http_method == "post":
        claim_id = get_named_property(event, "claim_id")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants