profile
viewpoint

Ask questionstasks.DynamoAttributeValue().withB double encoding value?

<!-- description of the bug: -->

I'm passing in a binary value to a step function which ends up getting base64 encoded somewhere along the way and it ends up getting base64 encoded a second time when I'm using withB as below. It's unclear from the current documentation if the string passed to withB should be base64 encoded already but it's type and the example seem to suggest it. If it's supposed to be a string of the raw binary is there a way decode an already base64 encoded string from the TaskInput.

The code I'm using to pass this value in as binary has been used in a couple other places using a couple different languages etc on the receiving end without issue. And no where am I knowingly encoding it a second time within the CDK state machine here.

withB's documentation shows

withB(value)🔹

public withB(value: string): DynamoAttributeValue
Parameters

value string
Returns

DynamoAttributeValue
Sets an attribute of type Binary.

For example: "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"

Reproduction Steps

<!-- minimal amount of code that causes the bug (if possible) or a reference: -->

    new tasks.DynamoUpdateItem({
        tableName: props.content.tableName,
        partitionKey: {
            name: "ContentID",
            value: new tasks.DynamoAttributeValue().withB(
                sfn.TaskInput.fromDataAt("$.ContentID").value
            ),
        },
        ...

Error Log

<!-- what is the error message you are seeing? -->

Environment

  • CLI Version : 1.36.1 (build 4df7dac)
  • Framework Version: 1.36.1 (build 4df7dac)
  • OS : macOS Catalina 10.15.5 Beta (19F62f)
  • Language : Typescript

Other

<!-- e.g. detailed explanation, stacktraces, related issues, suggestions on how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc -->


This is :bug: Bug Report

aws/aws-cdk

Answer questions eikeon

I need to add encoding='binary' to the above toString for this to work. But then I get

{
  "error": "ReferenceError",
  "cause": {
    "errorType": "ReferenceError",
    "errorMessage": "encoding is not defined",
    "trace": [
      "ReferenceError: encoding is not defined",
      "    at eval (eval at handler (/var/task/index.js:8:12), <anonymous>:1:76)",
      "    at Runtime.handler (/var/task/index.js:8:12)",
      "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
  }
}

Which works here docker run --rm -it --entrypoint node -v "$PWD":/var/task:ro,delegated lambci/lambda:nodejs10.x -p "Buffer.from('AQERFArszmn0KWJPnNOEEAewUpzQXvee', 'base64').toString(encoding='binary')"

Guessing EvaluateExpression is trying to do something with the encoding= bit

useful!

Related questions

Issues compiling CDK projects ("TS2300: Duplicate identifier 'IteratorResult'")
cli: cdk deploy issue hot 3
Subnet selection returns more than one per AZ hot 2
cli: synth fails if cdk.out does not exist hot 2
Default policy are getting creating even when Managed policy were created in the Role hot 1
Python dependency libraries are set to latest hot 1
using json instead of a string as context in cdk.json hot 1
Attaching Managed Policy to Role failing hot 1
Access denied when adding an event notification to an existing s3 bucket hot 1
Unable to create CfnSpotFleet using Python hot 1
DBClusterParameterGroup not found: default.aurora5.6 hot 1
aws-ecs: Cannot deploy fargate services with ECR images hot 1
ecs_patterns.ApplicationLoadBalancedFargateService should allow specifying healthCheck path - aws-cdk hot 1
CodeCommitSourceAction tries to add a policy to an imported role hot 1
Using getAtt that returns a list within a string that is joined in the generated template throws an error hot 1
Github User Rank List