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

ChangeDataCapture base64 encodes binary values #10

Open
Fasopus opened this issue Jul 29, 2022 · 1 comment
Open

ChangeDataCapture base64 encodes binary values #10

Fasopus opened this issue Jul 29, 2022 · 1 comment

Comments

@Fasopus
Copy link

Fasopus commented Jul 29, 2022

The dynamodb stream is emitting it's changes in json string format, with binary values being base64 encoded. However when performing the putitem command through boto, these strings are assumed to be un-encoded and go through an additional base64 encoding.

I was able to resolve this by transforming the binary objects into their bytes representations before sending them through boto

        if event_name == 'REMOVE':
            keys_to_delete = record['dynamodb']['Keys']

            # Look for binary values b64 decode them back into bytes
            for key in keys_to_delete:
                for valType in keys_to_delete[key]:
                    if valType == 'B':
                        keys_to_delete[key][valType] = base64.b64decode(keys_to_delete[key][valType])

            dynamodb.delete_item(TableName=target_ddb_name,Key=record['dynamodb']['Keys'])
        else:
            #print("Putting item")
            item_to_put = record['dynamodb']['NewImage']

            # Look for binary values b64 decode them back into bytes 
            for property in item_to_put:
                for valType in item_to_put[property]:
                    if valType == 'B':
                        item_to_put[property][valType] = base64.b64decode(item_to_put[property][valType])
            dynamodb.put_item(TableName=target_ddb_name,Item=item_to_put)
@esfinkel
Copy link

esfinkel commented Jun 5, 2024

I also had this issue and this solution worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants