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-custom-resource] response body is unusable #9969

Closed
ashald opened this issue Aug 25, 2020 · 0 comments · Fixed by #9977
Closed

[aws-custom-resource] response body is unusable #9969

ashald opened this issue Aug 25, 2020 · 0 comments · Fixed by #9977
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@ashald
Copy link

ashald commented Aug 25, 2020

Summary: AWS SDK returns API response body as a buffer that requires special handling. Without it, it's unusable as flatten function decomposes into a group of fields such as Body.0, Body.1, Body.2 etc, byte by byte.

Reproduction Steps

Example in Java:

AwsCustomResource.Builder.create(scope, id)
    .policy(
        AwsCustomResourcePolicy.fromSdkCalls(
            SdkCallsPolicyOptions.builder()
                .resources(ImmutableList.of(keyArn))
                .build()
        )
    )
    .onUpdate(
        AwsSdkCall.builder()
            .service("S3")
            .action("getObject")
            .parameters(ImmutableMap.of(
                "Bucket", bucket,
                "Key", key
            ))
            .physicalResourceId(PhysicalResourceId.of(key + "@" + Clock.systemUTC().millis()))
            .build()
    )
    .build()

CloudWatch logs show following:

{
    "Status": "SUCCESS",
    "Reason": "OK",
    "PhysicalResourceId": "<REDACTED>/vpc-id@1598324720636",
    "StackId": "<REDACTED>",
    "RequestId": "<REDACTED>",
    "LogicalResourceId": "GetVpcId1BE10C8B",
    "NoEcho": false,
    "Data": {
        "apiVersion": null,
        "region": "us-east-1",
        "AcceptRanges": "bytes",
        "ContentLength": 21,
        "ETag": "\"44b69b6234412df3a8fe5e4e7e8b917a\"",
        "ContentType": "application/octet-stream",
        "ServerSideEncryption": "AES256",
        "Body.0": 118,
        "Body.1": 112,
        "Body.2": 99,
        "Body.3": 45,
        "Body.4": 48,
        "Body.5": 49,
        "Body.6": 101,
        "Body.7": 55,
        "Body.8": 102,
        "Body.9": 48,
        "Body.10": 50,
        "Body.11": 57,
        "Body.12": 48,
        "Body.13": 98,
        "Body.14": 49,
        "Body.15": 48,
        "Body.16": 52,
        "Body.17": 48,
        "Body.18": 56,
        "Body.19": 101,
        "Body.20": 99
    }
}

What did you expect to happen?

At the very least, I expected Data object to have a key Body with content being a raw string.
Ideally, it'd be nice if we could attempt JSON-decode it in case response content type is application/json.

What actually happened?

Please see example above where response body is decomposed into a set of fields such as Body.0, Body.1, Body.2 etc, byte by byte.

Environment

  • CLI Version : 1.39
  • Framework Version: 1.39
  • Node.js Version: v12.18.0
  • OS : macOS
  • Language (Version): Java (8)

Other

While I'm not using the latest version of CDK, the latest source code indicates that the issues is still present: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/custom-resources/lib/aws-custom-resource/runtime/index.ts#L118-L122


This is 🐛 Bug Report

@ashald ashald added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 25, 2020
@ghost ghost changed the title [aws-custom-resource] response body in unusable [aws-custom-resource] response body is unusable Aug 25, 2020
jogold added a commit to jogold/aws-cdk that referenced this issue Aug 26, 2020
…sable

Convert buffers to strings when flattening the API response.

Closes aws#9969
@mergify mergify bot closed this as completed in #9977 Aug 28, 2020
mergify bot pushed a commit that referenced this issue Aug 28, 2020
…able (#9977)

Convert buffers to strings when flattening the API response.

Closes #9969, closes #10017


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
1 participant