Created
November 1, 2022 09:57
-
-
Save cal0610/b58d676a5fac19f2fecd20ab7d549829 to your computer and use it in GitHub Desktop.
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 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