Skip to content

Instantly share code, notes, and snippets.

@LucasVera
Created June 18, 2024 16:50
Show Gist options
  • Select an option

  • Save LucasVera/b9bff3a5d1f5b1a1c22b426927508b32 to your computer and use it in GitHub Desktop.

Select an option

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.
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