1

I'm currently attempting to create a mock integration using the python AWS CDK for the purpose of running integration tests in an app.

This app needs to query an external API to validate a payload. The endpoint expects a Content-Type application/vnd.nasa.cmr.umm+json;version=1.6.3. For now, I would like the MockIntegration to always return a 200 status code with an empty response.

This is what I tried:

from aws_cdk import aws_apigateway

cmr_api = aws_apigateway.RestApi(
    self, f"integration-test-cmr-api-try",
)

aws_apigateway.Resource(
    self, "mock-cmr-validation", parent=cmr_api.root, path_part="ingest"
).add_resource(
    "validate"
).add_method(
    http_method="POST",
    integration=aws_apigateway.MockIntegration(
                request_templates={
                    "application/vnd.nasa.cmr.umm+json;version=1.6.3":  json.dumps({"statusCode": 200})},
                integration_responses=[
                    {
                        "statusCode": "200",
                        "responseTemplates": {"application/json": json.dumps({})},
                    }
                ],
    ),
    method_responses=[
        {
            "statusCode": "200",
            "responseModels": {
                "application/json": aws_apigateway.Model.EMPTY_MODEL
            },
        }
    ],

)

Unfortunately a request to the generated gateway returns:

curl --request POST 'https://trfjg7ckha.execute-api.us-east-1.amazonaws.com/prod/ingest/validate' \
--header 'Content-Type: application/vnd.nasa.cmr.umm+json;version=1.6.3' \
--data-raw '{}'

Status code 500, {"message": "Internal server error"}.

Setting only application/json (or even application/vnd.nasa.cmr.umm+json) as the key in MockIntegration.request_templates, and using that as the Content-Type in the request, returns the intended result (status code 200, empty response). This makes me wonder if the issue can potentially be in setting the ;version=1.6.3 with the Content-Type?

Any help would be greatly appreciated!

1 Answers1

0

After some further experimentation, I was able to get pass this issue by using application/vnd.nasa.cmr.umm+json in the request_template (without the version). When that is the request_template content type, any application/vnd.nasa.cmr.umm+json;version=XXX matches and the correct mock integration is triggered!