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

@wong-a Yes, I was expecting the binary value to behave like the low-level API. And since we’re in this JSON-based context passing binary with type string — I assumed it’d need to be expecting base64 encoded string for it to work.

I’ve been passing the binary around with the various AWS SDKs as you describe. And by the time the data gets to were I was trying to use tasks.DynamoUpdateItem above within the state machine the ContentID is already base64 encoded since ASL is JSON-based. Normally if the SDKs encode something on the way in they decode it on the way out or the other way around.

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