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

Marshalled data returned from CallAwsService DynamoDB query has incorrect casing in type names #4294

Open
Bee-Taylor opened this issue Dec 1, 2022 · 4 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@Bee-Taylor
Copy link

Describe the bug

When running the step function task CallAwsService to query a database in dynamodb, the returned items have incorrect casing in type names. More specifically, "BOOL" is returned as "Bool" which means the included unmarshall function throws an error

Expected Behavior

When running CallAwsService to query a db, it should return data in the form:

{
  "Items": [
    {
      "example": {
        "BOOL": true
      }
    }
  ]
}

Current Behavior

When running CallAwsService to query a db, it returns:

{
  "Items": [
    {
      "example": {
        "Bool": true
      }
    }
  ]
}

Reproduction Steps

The following step function:

{
  "StartAt": "DBQuery",
  "States": {
    "DBQuery": {
      "End": true,
      "Type": "Task",
      "Resource": "arn:aws:states:::aws-sdk:dynamodb:query",
      "Parameters": {
        "TableName": "{tablename}",
        "KeyConditionExpression": "#{key} = :{key}",
        "ExpressionAttributeNames": {
          "#{key}": "{key}"
        },
        "ExpressionAttributeValues": {
          ":scopeId": {
            "S.$": "$.path.{key}"
          }
        },
        "IndexName": "{indexname}"
      }
    }
  },
  "TimeoutSeconds": 300
}

Replacing tablename with an existing table, key with the partition key of a gsi, indexname with the name of a gsi on the table, giving it the necessary permissions, and running with payload:

{
  "path": {
    "{key}": "{value}"
  }
}

Possible Solution

I imagine this should be a case of changing a hardcoded value from Bool to BOOL somewhere in the codebase, but if not, if the unmarshall function was able to deal with typenames insensitive of casing, that would also fix the problem

Additional Information/Context

No response

SDK version used

Unsure, probably latest

Environment details (OS name and version, etc.)

Called from a step function

@Bee-Taylor Bee-Taylor added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 1, 2022
@ajredniwja
Copy link
Member

Hey @Bee-Taylor thanks for opening this issue can you please share the code you are using and please confirm the version of the SDK as well?

@ajredniwja ajredniwja removed the needs-triage This issue or PR still needs to be triaged. label Dec 2, 2022
@ajredniwja ajredniwja self-assigned this Dec 2, 2022
@ajredniwja ajredniwja added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p2 This is a standard priority issue labels Dec 2, 2022
@Bee-Taylor
Copy link
Author

Bee-Taylor commented Dec 6, 2022

Hi, so since this is calling SDK from step functions I'm not 100% sure if this is the right repo to ask this in, feel free to send me to a different repo if not

The dynamodb query operation is called from a step function defined in CDK, like:

  return new CallAwsService(scope, `${id}-ddbQuery`, {
    service: 'DynamoDB',
    action: 'query',
    parameters: {
      TableName: table.tableName,
      ...parameters,
    },
    iamResources: [table.tableArn, ...(IndexName ? [`${table.tableArn}/index/${IndexName}`] : [])],
    iamAction: 'dynamodb:Query',
  })

Where Table is a dynamodb table, and indexname is the name of a gsi on that table

In terms of versions, these are my aws versions in package.json:

    "aws-cdk": "^2.31.2",
    "aws-cdk-lib": "^2.31.2",
    "@aws-sdk/client-dynamodb": "^3.204.0",
    "@aws-sdk/lib-dynamodb": "^3.204.0",
    "@aws-sdk/util-dynamodb": "^3.204.0",

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Dec 7, 2022
@JoeWHoward
Copy link

+1 for this, we just ran into it. Specifically when querying a DynamoDB table from the native step function action (resource arn:aws:states:::aws-sdk:dynamodb:query) we receive a marshalled DDB object in which top-level attributes are "BOOL" but any booleans nested in a map are "Bool".

We got around this by casting type/marshall attributes to uppercase in a custom implementation of the unmarshalling function.

@dparish
Copy link

dparish commented Mar 1, 2024

Good god this is dumb. I have to write an intermediate layer to turn Bool to BOOL and Nul to NULL. Please fix this.

Step functions have enough quirks. This one is just ridiculous.

Here is my hack to fix this:

  const cleanedPayload = JSON.stringify(payload)
    .replace(/"Nul":/g, '"NULL":')
    .replace(/"Bool":/g, '"BOOL":');
  return unmarshall(JSON.parse(cleanedPayload));

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. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

4 participants