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

Bug: Swagger UI doesn't load : Loading... with Uncaught SyntaxError #3552

Closed
filol opened this issue Dec 22, 2023 · 9 comments · Fixed by #3562
Closed

Bug: Swagger UI doesn't load : Loading... with Uncaught SyntaxError #3552

filol opened this issue Dec 22, 2023 · 9 comments · Fixed by #3562
Assignees
Labels
documentation Improvements or additions to documentation feature-request feature request

Comments

@filol
Copy link

filol commented Dec 22, 2023

Expected Behaviour

Having swagger UI displayed

Current Behaviour

image

Uncaught SyntaxError: Unexpected token '<' (at swagger.js:1:1)
swagger:543 Uncaught ReferenceError: SwaggerUIBundle is not defined
at swagger:543:7

Code snippet

import os

from aws_lambda_powertools import Logger, Metrics, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext
from boto_session_manager import BotoSesManager
from mypy_boto3_cognito_idp.type_defs import (
    CreateUserPoolClientRequestRequestTypeDef,
    CreateUserPoolClientResponseTypeDef,
)

from .utils import create_type_with_keys_removed

bsm = BotoSesManager()
app = APIGatewayRestResolver(enable_validation=True)
app.enable_swagger(
    path="/swagger"

)
tracer = Tracer()
logger = Logger()
metrics = Metrics(namespace="UserPoolsManagement", service="api-cognito-awslz-totalenergies")

cognito_idp_client = bsm.cognitoidentityprovider_client


@app.post("/v2/<user_pool_id>/user_pool_client")
@tracer.capture_method
def create_user_pool_client(
    user_pool_id: str, user_pool_client_body: create_type_with_keys_removed(CreateUserPoolClientRequestRequestTypeDef, ["UserPoolId"])
) -> CreateUserPoolClientResponseTypeDef:
    user_pool_client_body["UserPoolId"] = user_pool_id
    response = cognito_idp_client.create_user_pool_client(**user_pool_client_body)

    return response


@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@tracer.capture_lambda_handler
@metrics.log_metrics(capture_cold_start_metric=True)
def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

Possible Solution

No response

Steps to Reproduce

Having a lambda behind a edge API Gateway with a proxy+ to the lambda

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.11

Packaging format used

Lambda Layers, PyPi

Debugging logs

INIT_START Runtime Version: python:3.11.v24 Runtime Version ARN: arn:aws:lambda:eu-central-1::runtime:a5ffc62d98071fc767e6f8abc670b5036a0f5a683f0bbc6cb1bac14de89647bf

2023-12-22T15:38:56.940+01:00	/var/task/aws_lambda_powertools/event_handler/api_gateway.py:1772: UserWarning: POWERTOOLS_DEV environment variable is enabled. Increasing verbosity across utilities.

2023-12-22T15:38:56.940+01:00	return powertools_dev_is_set()

2023-12-22T15:38:57.222+01:00	/var/task/aws_lambda_powertools/logging/formatter.py:129: UserWarning: POWERTOOLS_DEV environment variable is enabled. Increasing verbosity across utilities.

2023-12-22T15:38:57.222+01:00

Copy
constants.PRETTY_INDENT if powertools_dev_is_set() else constants.COMPACT_INDENT
constants.PRETTY_INDENT if powertools_dev_is_set() else constants.COMPACT_INDENT

2023-12-22T15:38:57.373+01:00	START RequestId: 2ac64ee7-a3cd-4332-a9aa-0100d3e0cdea Version: $LATEST

2023-12-22T15:38:57.374+01:00	{

2023-12-22T15:38:57.374+01:00	"level":"INFO",

2023-12-22T15:38:57.374+01:00	"location":"decorate:451",

2023-12-22T15:38:57.374+01:00	"message":{

2023-12-22T15:38:57.374+01:00	"resource":"/{proxy+}",

2023-12-22T15:38:57.374+01:00	"path":"/swagger",

2023-12-22T15:38:57.374+01:00	"httpMethod":"GET",

2023-12-22T15:38:57.374+01:00

Copy
"headers":{
"headers":{

2023-12-22T15:38:57.374+01:00	"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",

2023-12-22T15:38:57.374+01:00	"Accept-Encoding":"gzip, deflate, br",

2023-12-22T15:38:57.374+01:00	"Accept-Language":"fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",

2023-12-22T15:38:57.374+01:00	"cache-control":"max-age=0",

2023-12-22T15:38:57.374+01:00	"CloudFront-Forwarded-Proto":"https",

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-Desktop-Viewer":"true",

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-Mobile-Viewer":"false",

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-SmartTV-Viewer":"false",

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-Tablet-Viewer":"false",

2023-12-22T15:38:57.374+01:00	"CloudFront-Viewer-ASN":"12322",

2023-12-22T15:38:57.374+01:00	"CloudFront-Viewer-Country":"FR",

2023-12-22T15:38:57.374+01:00	"Host":"exqimk94h0.execute-api.eu-central-1.amazonaws.com",

2023-12-22T15:38:57.374+01:00	"sec-ch-ua":"\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",

2023-12-22T15:38:57.374+01:00	"sec-ch-ua-mobile":"?0",

2023-12-22T15:38:57.374+01:00	"sec-ch-ua-platform":"\"Windows\"",

2023-12-22T15:38:57.374+01:00	"sec-fetch-dest":"document",

2023-12-22T15:38:57.374+01:00	"sec-fetch-mode":"navigate",

2023-12-22T15:38:57.374+01:00	"sec-fetch-site":"none",

2023-12-22T15:38:57.374+01:00	"sec-fetch-user":"?1",

2023-12-22T15:38:57.374+01:00	"upgrade-insecure-requests":"1",

2023-12-22T15:38:57.374+01:00	"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",

2023-12-22T15:38:57.374+01:00	"Via":"2.0 4ab6741feebe4ae20194f9a14d724e64.cloudfront.net (CloudFront)",

2023-12-22T15:38:57.374+01:00	"X-Amz-Cf-Id":"2zmOMChfaSCXWS3JiA6LprLK10SDk2CfdvGwf9VbqUVCMaU7c9X4IQ==",

2023-12-22T15:38:57.374+01:00	"X-Amzn-Trace-Id":"Root=1-65859f7f-1f16bda9774b1deb5710ee9a",

2023-12-22T15:38:57.374+01:00	"X-Forwarded-For":"91.167.206.249, 130.176.186.164",

2023-12-22T15:38:57.374+01:00	"X-Forwarded-Port":"443",

2023-12-22T15:38:57.374+01:00	"X-Forwarded-Proto":"https"

2023-12-22T15:38:57.374+01:00	},

2023-12-22T15:38:57.374+01:00	"multiValueHeaders":{

2023-12-22T15:38:57.374+01:00	"Accept":[

2023-12-22T15:38:57.374+01:00	"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"Accept-Encoding":[

2023-12-22T15:38:57.374+01:00	"gzip, deflate, br"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"Accept-Language":[

2023-12-22T15:38:57.374+01:00	"fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"cache-control":[

2023-12-22T15:38:57.374+01:00	"max-age=0"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Forwarded-Proto":[

2023-12-22T15:38:57.374+01:00	"https"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-Desktop-Viewer":[

2023-12-22T15:38:57.374+01:00	"true"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-Mobile-Viewer":[

2023-12-22T15:38:57.374+01:00	"false"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-SmartTV-Viewer":[

2023-12-22T15:38:57.374+01:00	"false"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Is-Tablet-Viewer":[

2023-12-22T15:38:57.374+01:00	"false"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Viewer-ASN":[

2023-12-22T15:38:57.374+01:00	"12322"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"CloudFront-Viewer-Country":[

2023-12-22T15:38:57.374+01:00	"FR"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"Host":[

2023-12-22T15:38:57.374+01:00	"exqimk94h0.execute-api.eu-central-1.amazonaws.com"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-ch-ua":[

2023-12-22T15:38:57.374+01:00	"\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-ch-ua-mobile":[

2023-12-22T15:38:57.374+01:00	"?0"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-ch-ua-platform":[

2023-12-22T15:38:57.374+01:00	"\"Windows\""

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-fetch-dest":[

2023-12-22T15:38:57.374+01:00	"document"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-fetch-mode":[

2023-12-22T15:38:57.374+01:00	"navigate"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-fetch-site":[

2023-12-22T15:38:57.374+01:00	"none"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"sec-fetch-user":[

2023-12-22T15:38:57.374+01:00	"?1"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"upgrade-insecure-requests":[

2023-12-22T15:38:57.374+01:00	"1"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"User-Agent":[

2023-12-22T15:38:57.374+01:00	"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"Via":[

2023-12-22T15:38:57.374+01:00	"2.0 4ab6741feebe4ae20194f9a14d724e64.cloudfront.net (CloudFront)"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"X-Amz-Cf-Id":[

2023-12-22T15:38:57.374+01:00	"2zmOMChfaSCXWS3JiA6LprLK10SDk2CfdvGwf9VbqUVCMaU7c9X4IQ=="

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"X-Amzn-Trace-Id":[

2023-12-22T15:38:57.374+01:00	"Root=1-65859f7f-1f16bda9774b1deb5710ee9a"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"X-Forwarded-For":[

2023-12-22T15:38:57.374+01:00	"91.167.206.249, 130.176.186.164"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"X-Forwarded-Port":[

2023-12-22T15:38:57.374+01:00	"443"

2023-12-22T15:38:57.374+01:00	],

2023-12-22T15:38:57.374+01:00	"X-Forwarded-Proto":[

2023-12-22T15:38:57.374+01:00	"https"

2023-12-22T15:38:57.374+01:00	]

2023-12-22T15:38:57.374+01:00	},

2023-12-22T15:38:57.374+01:00	"queryStringParameters":null,

2023-12-22T15:38:57.374+01:00	"multiValueQueryStringParameters":null,

2023-12-22T15:38:57.374+01:00	"pathParameters":{

2023-12-22T15:38:57.374+01:00	"proxy":"swagger"

2023-12-22T15:38:57.374+01:00	},

2023-12-22T15:38:57.374+01:00	"stageVariables":null,

2023-12-22T15:38:57.374+01:00	"requestContext":{

2023-12-22T15:38:57.374+01:00	"resourceId":"nql3wf",

2023-12-22T15:38:57.374+01:00	"resourcePath":"/{proxy+}",

2023-12-22T15:38:57.374+01:00	"httpMethod":"GET",

2023-12-22T15:38:57.374+01:00	"extendedRequestId":"QWXcAGzeFiAEbRg=",

2023-12-22T15:38:57.374+01:00	"requestTime":"22/Dec/2023:14:38:55 +0000",

2023-12-22T15:38:57.374+01:00	"path":"/sdx/swagger",

2023-12-22T15:38:57.374+01:00	"accountId":"143192094220",

2023-12-22T15:38:57.374+01:00	"protocol":"HTTP/1.1",

2023-12-22T15:38:57.374+01:00	"stage":"sdx",

2023-12-22T15:38:57.374+01:00	"domainPrefix":"exqimk94h0",

2023-12-22T15:38:57.374+01:00	"requestTimeEpoch":1703255935751,

2023-12-22T15:38:57.374+01:00	"requestId":"02c8f7cc-3ac2-4ea9-88da-81d4a8c05fdd",

2023-12-22T15:38:57.374+01:00	"identity":{

2023-12-22T15:38:57.374+01:00	"cognitoIdentityPoolId":null,

2023-12-22T15:38:57.374+01:00	"accountId":null,

2023-12-22T15:38:57.374+01:00	"cognitoIdentityId":null,

2023-12-22T15:38:57.374+01:00	"caller":null,

2023-12-22T15:38:57.374+01:00	"sourceIp":"91.167.206.249",

2023-12-22T15:38:57.374+01:00	"principalOrgId":null,

2023-12-22T15:38:57.374+01:00	"accessKey":null,

2023-12-22T15:38:57.374+01:00	"cognitoAuthenticationType":null,

2023-12-22T15:38:57.374+01:00	"cognitoAuthenticationProvider":null,

2023-12-22T15:38:57.374+01:00	"userArn":null,

2023-12-22T15:38:57.374+01:00	"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",

2023-12-22T15:38:57.374+01:00	"user":null

2023-12-22T15:38:57.374+01:00	},

2023-12-22T15:38:57.374+01:00	"domainName":"exqimk94h0.execute-api.eu-central-1.amazonaws.com",

2023-12-22T15:38:57.374+01:00	"apiId":"exqimk94h0"

2023-12-22T15:38:57.374+01:00	},

2023-12-22T15:38:57.374+01:00	"body":null,

2023-12-22T15:38:57.374+01:00	"isBase64Encoded":false

2023-12-22T15:38:57.374+01:00	},

2023-12-22T15:38:57.374+01:00	"timestamp":"2023-12-22 14:38:57,374+0000",

2023-12-22T15:38:57.374+01:00	"service":"cognito-management-te",

2023-12-22T15:38:57.374+01:00	"cold_start":true,

2023-12-22T15:38:57.374+01:00	"function_name":"cognito-management-te-sdx-api-user-pool-management",

2023-12-22T15:38:57.374+01:00	"function_memory_size":"128",

2023-12-22T15:38:57.374+01:00	"function_arn":"arn:aws:lambda:eu-central-1:143192094220:function:cognito-management-te-sdx-api-user-pool-management",

2023-12-22T15:38:57.374+01:00	"function_request_id":"2ac64ee7-a3cd-4332-a9aa-0100d3e0cdea",

2023-12-22T15:38:57.374+01:00	"correlation_id":"02c8f7cc-3ac2-4ea9-88da-81d4a8c05fdd",

2023-12-22T15:38:57.374+01:00	"xray_trace_id":"1-65859f7f-1f16bda9774b1deb5710ee9a"

2023-12-22T15:38:57.374+01:00	}

2023-12-22T15:38:57.379+01:00	{"resource":"/{proxy+}","path":"/swagger","httpMethod":"GET","headers":{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7","Accept-Encoding":"gzip, deflate, br","Accept-Language":"fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7","cache-control":"max-age=0","CloudFront-Forwarded-Proto":"https","CloudFront-Is-Desktop-Viewer":"true","CloudFront-Is-Mobile-Viewer":"false","CloudFront-Is-SmartTV-Viewer":"false","CloudFront-Is-Tablet-Viewer":"false","CloudFront-Viewer-ASN":"12322","CloudFront-Viewer-Country":"FR","Host":"exqimk94h0.execute-api.eu-central-1.amazonaws.com","sec-ch-ua":"\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"Windows\"","sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Via":"2.0 4ab6741feebe4ae20194f9a14d724e64.cloudfront.net (CloudFront)","X-Amz-Cf-Id":"2zmOMChfaSCXWS3JiA6LprLK10SDk2CfdvGwf9VbqUVCMaU7c9X4IQ==","X-Amzn-Trace-Id":"Root=1-65859f7f-1f16bda9774b1deb5710ee9a","X-Forwarded-For":"91.167.206.249, 130.176.186.164","X-Forwarded-Port":"443","X-Forwarded-Proto":"https"},"multiValueHeaders":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"],"cache-control":["max-age=0"],"CloudFront-Forwarded-Proto":["https"],"CloudFront-Is-Desktop-Viewer":["true"],"CloudFront-Is-Mobile-Viewer":["false"],"CloudFront-Is-SmartTV-Viewer":["false"],"CloudFront-Is-Tablet-Viewer":["false"],"CloudFront-Viewer-ASN":["12322"],"CloudFront-Viewer-Country":["FR"],"Host":["exqimk94h0.execute-api.eu-central-1.amazonaws.com"],"sec-ch-ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"sec-ch-ua-mobile":["?0"],"sec-ch-ua-platform":["\"Windows\""],"sec-fetch-dest":["document"],"sec-fetch-mode":["navigate"],"sec-fetch-site":["none"],"sec-fetch-user":["?1"],"upgrade-insecure-requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Via":["2.0 4ab6741feebe4ae20194f9a14d724e64.cloudfront.net (CloudFront)"],"X-Amz-Cf-Id":["2zmOMChfaSCXWS3JiA6LprLK10SDk2CfdvGwf9VbqUVCMaU7c9X4IQ=="],"X-Amzn-Trace-Id":["Root=1-65859f7f-1f16bda9774b1deb5710ee9a"],"X-Forwarded-For":["91.167.206.249, 130.176.186.164"],"X-Forwarded-Port":["443"],"X-Forwarded-Proto":["https"]},"queryStringParameters":null,"multiValueQueryStringParameters":null,"pathParameters":{"proxy":"swagger"},"stageVariables":null,"requestContext":{"resourceId":"nql3wf","resourcePath":"/{proxy+}","httpMethod":"GET","extendedRequestId":"QWXcAGzeFiAEbRg=","requestTime":"22/Dec/2023:14:38:55 +0000","path":"/sdx/swagger","accountId":"143192094220","protocol":"HTTP/1.1","stage":"sdx","domainPrefix":"exqimk94h0","requestTimeEpoch":1703255935751,"requestId":"02c8f7cc-3ac2-4ea9-88da-81d4a8c05fdd","identity":{"cognitoIdentityPoolId":null,"accountId":null,"cognitoIdentityId":null,"caller":null,"sourceIp":"91.167.206.249","principalOrgId":null,"accessKey":null,"cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":null,"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","user":null},"domainName":"exqimk94h0.execute-api.eu-central-1.amazonaws.com","apiId":"exqimk94h0"},"body":null,"isBase64Encoded":false}

2023-12-22T15:38:57.379+01:00	Processing Route:::swagger_handler (/swagger)

2023-12-22T15:38:57.379+01:00	Middleware Stack:

2023-12-22T15:38:57.379+01:00	=================

2023-12-22T15:38:57.379+01:00	OpenAPIValidationMiddleware

2023-12-22T15:38:57.379+01:00	_registered_api_adapter

2023-12-22T15:38:57.379+01:00	=================

2023-12-22T15:38:57.648+01:00	Processed Middlewares:

2023-12-22T15:38:57.648+01:00	======================

2023-12-22T15:38:57.648+01:00	[OpenAPIValidationMiddleware] next call chain is OpenAPIValidationMiddleware -> _registered_api_adapter

2023-12-22T15:38:57.648+01:00	[_registered_api_adapter] next call chain is _registered_api_adapter -> swagger_handler

2023-12-22T15:38:57.648+01:00	======================

2023-12-22T15:38:57.779+01:00	{"_aws":{"Timestamp":1703255937778,"CloudWatchMetrics":[{"Namespace":"UserPoolsManagement","Dimensions":[["function_name","service"]],"Metrics":[{"Name":"ColdStart","Unit":"Count"}]}]},"function_name":"cognito-management-te-sdx-api-user-pool-management","service":"api-cognito-awslz-totalenergies","ColdStart":[1.0]}

2023-12-22T15:38:57.779+01:00	/var/task/aws_lambda_powertools/metrics/provider/base.py:209: UserWarning: No application metrics to publish. The cold-start metric may be published if enabled. If application metrics should never be empty, consider using 'raise_on_empty_metrics'

2023-12-22T15:38:57.779+01:00	self.flush_metrics(raise_on_empty_metrics=raise_on_empty_metrics)

2023-12-22T15:38:57.802+01:00	END RequestId: 2ac64ee7-a3cd-4332-a9aa-0100d3e0cdea

2023-12-22T15:38:57.802+01:00	REPORT RequestId: 2ac64ee7-a3cd-4332-a9aa-0100d3e0cdea Duration: 429.04 ms Billed Duration: 430 ms Memory Size: 128 MB Max Memory Used: 86 MB Init Duration: 1315.91 ms XRAY TraceId: 1-65859f7f-1f16bda9774b1deb5710ee9a SegmentId: 21fee44477b3084d Sampled: true
@filol filol added bug Something isn't working triage Pending triage from maintainers labels Dec 22, 2023
@rubenfonseca
Copy link
Contributor

Hi @filol can you show me the Network tab of the browser to see which URL is giving out that "Syntax error" error?

@filol
Copy link
Author

filol commented Dec 22, 2023

Hi @rubenfonseca

There is :
image

image

But I found the problem ! I have inspected the files receives and each time it was the HTML content even for the js & css file. It was related to the API cache that was enable. Not sure you can do something about it. Just maybe display this info on the documentation

@rubenfonseca
Copy link
Contributor

Awesome! So in this case, /swagger.js and /swagger.css were serving cached versions of /swagger is that correct?

@filol
Copy link
Author

filol commented Dec 22, 2023

@rubenfonseca Yes ! See the file selected in my 2nd screenshot. It's /swagger.js but the content is real content is HTML. That's why we get a syntax error, html code in javascript is not correct

@rubenfonseca
Copy link
Contributor

Interesting! Let's keep the issue open so we can add a note in the documentation. Thank you for this!

@rubenfonseca rubenfonseca removed the triage Pending triage from maintainers label Dec 22, 2023
@rubenfonseca rubenfonseca moved this from Triage to Backlog in Powertools for AWS Lambda (Python) Dec 22, 2023
@leandrodamascena
Copy link
Contributor

Hey everyone! I was reading this issue to see if we can help on the Powertools side, but I don't think we can do anything. Just to clarify the issue and help us decide the next steps:

1 - Amazon API Gateway caches values based on the resource name and/or query string parameters. In this case, the cache will store the {/proxy+} resource. Just to simplify my explanation, I will assume that you are using Amazon API Gateway just to serve the Swagger file. In this case, Amazon API Gateway will cache the first request for {proxy+} which is /swagger (HTML). Subsequent requests for {/proxy+} will be /swagger.js and /swagger.json, and Amazon API Gateway will serve the HTML because the cache for the resource {/proxy+} is the HTML created by the first request /swagger.

2 - Amazon API Gateway does not depend on/use any header sent by downstream integration, in this case Lambda. The cache must be invalidated by the client, so we have nothing to do on the server side.
Reference: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html

A client of your API can invalidate an existing cache entry and reload it from the integration endpoint for individual requests. The client must send a request that contains the Cache-Control: max-age=0 header. The client receives the response directly from the integration endpoint instead of the cache, provided that the client is authorized to do so. This replaces the existing cache entry with the new response, which is fetched from the integration endpoint.

3 - You can solve this by creating specific resources for each path, like this:
image

4 - I found another small problem when we served the CSS/JS from Powertools. In the files swagger-ui-bundle.min.js and swagger-ui.min.css we have the sourceMappingURL configuration at the end of them, which causes the browser to try to find the map debug files when someone opens the developer tools. This raises a 404 because we don't have this map file (we don't need it - we are not debugging the files) and 2 more executions in Lambda, which is not necessary.
image

So, as the next steps we have:

1 - Update our documentation to clarify the issue when using {proxy+} and cache in Amazon API Gateway.
2 - Remove the sourceMappingURL configuration.

I will work on both items and submit a PR.

Thanks again for opening this issue @filol and helping us make Powertools for AWS Lambda even better for our customers. Please let me know if you have any questions.

@leandrodamascena
Copy link
Contributor

We've modified the PR and we'll inject CSS and JS inline into the SwaggerUI HTML file. This way we reduce the number of Lambda invocations, optimize code execution, and fix caching issues.

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jan 10, 2024
Copy link
Contributor

This is now released under 2.32.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jan 19, 2024
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature-request feature request
Projects
Status: Shipped
3 participants