Created
June 18, 2024 16:50
-
-
Save LucasVera/b9bff3a5d1f5b1a1c22b426927508b32 to your computer and use it in GitHub Desktop.
Simple example showing a javascript appsync resolver that leverages the use of directy dynamodb integration to perform an "update item" on a dynamodb table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function request (ctx) { | |
| const { args } = ctx; | |
| const { blogPost } = args; | |
| // Any validation logic or transformation/mapping logic | |
| return { | |
| operation: 'UpdateItem', | |
| key: util.dynamodb.toMapValues({ BlogPostId: blogPost.id }), | |
| update: { | |
| expression: 'SET #BlogPost = :blogPost', | |
| expressionNames: { '#BlogPost': 'BlogPost' }, | |
| expressionValues: { | |
| ':blogPost': util.dynamodb.toDynamoDB(blogPost), | |
| } | |
| }, | |
| }; | |
| } | |
| export function response (ctx) { | |
| const { result } = ctx; | |
| // ... any transformation/mapping logic, etc | |
| return result.Attributes.BlogPost; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment