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

AWS Observability Instrumentation breaks HTTP API lambda functions when using response format 2.0 #884

Open
dpeters1 opened this issue Oct 4, 2023 · 0 comments

Comments

@dpeters1
Copy link

dpeters1 commented Oct 4, 2023

After setting up instrumentation in the new serverless dashboard, all of our API endpoints return a 500 - Internal Server Error code.

Peeking into the logs, this is caused by serverless looking for a dict response with statusCode key that is not required by AWS HTTP API V2 response format.

{
    "source": "serverlessSdk",
    "type": "ERROR_TYPE_CAUGHT_SDK_INTERNAL",
    "name": "AttributeError",
    "message": "'str' object has no attribute 'get'",
    "stack": "Traceback (most recent call last):\n  File \"/opt/python/serverless_aws_lambda_sdk/instrument/__init__.py\", line 483, in _close_trace\n    resolve_response_tags(outcome_result)\n  File \"/opt/python/serverless_aws_lambda_sdk/instrument/lib/response_tags.py\", line 11, in resolve\n    status_code = response and response.get(\"statusCode\")\nAttributeError: 'str' object has no attribute 'get'\n",
    "description": "Internal Serverless SDK Error. Please report at https://github.com/serverless/console/issue"
}

Per AWS documentation, it is valid to return a string response and API gateway will convert it to a dictionary:

With the 2.0 format version, API Gateway can infer the response format for you. API Gateway makes the following assumptions if your Lambda function returns valid JSON and doesn't return a statusCode:

  • isBase64Encoded is false.
  • statusCode is 200.
  • content-type is application/json.
  • body is the function's response.
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

1 participant