Skip to content

Instantly share code, notes, and snippets.

@cal0610
Created November 1, 2022 09:57
Show Gist options
  • Save cal0610/b58d676a5fac19f2fecd20ab7d549829 to your computer and use it in GitHub Desktop.
Save cal0610/b58d676a5fac19f2fecd20ab7d549829 to your computer and use it in GitHub Desktop.
import * as AWS from "aws-sdk";
const TABLE_NAME = process.env.STORE_TABLE_NAME || "";
const PRIMARY_KEY = process.env.STORE_PRIMARY_KEY || "";
const db = new AWS.DynamoDB.DocumentClient();
export const handler = async (event: any = {}): Promise<any> => {
const requestedItemId = event.pathParameters.id;
if (!requestedItemId) {
return {
statusCode: 400,
body: `Error: You are missing the path parameter id`,
};
}
const params = {
TableName: TABLE_NAME,
Key: {
[PRIMARY_KEY]: requestedItemId,
},
};
try {
await db.delete(params).promise();
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
},
body: "",
};
} catch (dbError: any) {
return { statusCode: 500, body: JSON.stringify(dbError) };
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment