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
| const { UpdateItemCommand, DynamoDBClient } = require('@aws-sdk/client-dynamodb'); | |
| const { marshall } = require('@aws-sdk/util-dynamodb'); | |
| const { inspect } = require('util'); | |
| const client = new DynamoDBClient({ region: 'us-east-1' }); | |
| // Update an item's property which is nested in a map | |
| const main = async () => { | |
| try { |
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
| const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager'); | |
| const secretsManagerClient = new SecretsManagerClient({ region: 'us-east-1' }); // Replace with configured region in the IaC or environment | |
| const getSecretValue = (SecretId) => { | |
| const params = { | |
| SecretId, | |
| }; | |
| const command = new GetSecretValueCommand(params); |
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: { |
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
| import { DynamoDBClient } from "@aws-sdk/client-dynamodb" | |
| import { QueryCommand } from "@aws-sdk/lib-dynamodb" | |
| import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb" | |
| const client = new DynamoDBClient({}) | |
| const ddbDocClient = DynamoDBDocumentClient.from(client) | |
| /** | |
| * Get all orders for a user | |
| * Using single table design, we can query the table to get all orders for a user |
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
| const sleep = (ms: number) => new Promise(resolve => setTimeout(() => resolve('done'), ms)) | |
| type RetrierOptions<T> = { | |
| maxRetries?: number | |
| delay?: number | |
| functionToRetry: () => Promise<T> | |
| } | |
| const withRetry = async <T>(options: RetrierOptions<T>): Promise<T> => { | |
| const { maxRetries = 3, delay = 1000, functionToRetry } = options |