This file contains 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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"execute-api:ManageConnections" | |
], | |
"Resource": "*" | |
} |
This file contains 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 fromArrayToSet(values: string[]) { | |
if (!values || values.length === 0) { | |
throw Error('Cannot convert empty array into a set'); | |
} | |
return DynamoDB.createSet(values); | |
} |
This file contains 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
// credentials are stored in a .env file with the following contents: | |
// | |
// accessKeyId= | |
// secretAccessKey= | |
// region= | |
// tableName= | |
// See: https://github.com/motdotla/dotenv | |
require("dotenv").config(); |
This file contains 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
async function deleteFriendByValue(friendName: string) { | |
const Key = { id: "1234" }; | |
// Delete the value from the set. This operation is idempotent and will not | |
// produce an error if the value(s) are missing. | |
const { err, data } = await updateWithErrorWrapper({ | |
TableName, | |
Key, | |
UpdateExpression: `DELETE friends :valuesToRemove`, | |
ExpressionAttributeValues: { | |
":valuesToRemove": DynamoDB.createSet([friendName]) |
This file contains 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
// credentials are stored in a .env file with the following contents: | |
// | |
// accessKeyId= | |
// secretAccessKey= | |
// region= | |
// tableName= | |
// See: https://github.com/motdotla/dotenv | |
require("dotenv").config(); |
This file contains 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
function toArrayfromSet(set) { | |
if (!set) return []; | |
if (Array.isArray(set)) return set; | |
return Array.isArray(set.values) ? set.values : []; | |
} |
This file contains 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 result = await DynamoDB.get({ | |
TableName, | |
Key: { id: "1234" } | |
}).promise(); | |
console.log(result.Item.friends); | |
console.log(Array.isArray(result.Item.friends.values)); | |
// Output: | |
Set { | |
wrapperName: 'Set', |
This file contains 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
async function deleteFriendByValue(friendName) { | |
const Key = { id: "1234" }; | |
// fetch the document | |
let result = await DynamoDB.get({ | |
TableName, | |
Key | |
}).promise(); | |
// Delete the value from the set. This operation is idempotent and will not produce an error if the value(s) are missing. |
This file contains 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 * as AWS from "aws-sdk"; | |
const DynamoDB = new AWS.DynamoDB.DocumentClient(); | |
DynamoDB.put({ | |
TableName, | |
Item: { | |
id: "1234", | |
name: "carl", | |
friends: DynamoDB.createSet(["meatwad", "frylock", "shake"]) | |
} |
This file contains 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
async function conditionalVersionRemoveFriendByValue(friendName) { | |
const Key = { id: "1234" }; | |
// fetch the document | |
const document = (await DynamoDB.get({ | |
TableName, | |
Key | |
}).promise()).Item; | |
// find the index |
NewerOlder