-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5d16ff
commit 17abf9f
Showing
5 changed files
with
48 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb'; | ||
import { DynamoDB } from '@aws-sdk/client-dynamodb'; | ||
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb" | ||
import { DynamoDB } from "@aws-sdk/client-dynamodb" | ||
|
||
const TABLE_NAME = process.env.TABLE_NAME || ''; | ||
const TABLE_NAME = process.env.TABLE_NAME || "" | ||
|
||
const db = DynamoDBDocument.from(new DynamoDB()); | ||
const db = DynamoDBDocument.from(new DynamoDB()) | ||
|
||
export const handler = async (): Promise<any> => { | ||
|
||
const params = { | ||
TableName: TABLE_NAME | ||
}; | ||
TableName: TABLE_NAME, | ||
} | ||
|
||
try { | ||
const response = await db.scan(params); | ||
return { statusCode: 200, body: JSON.stringify(response.Items) }; | ||
const response = await db.scan(params) | ||
console.log("Retrieve Success; ", { | ||
statusCode: 200, | ||
body: JSON.stringify(response.Items), | ||
}) | ||
return { statusCode: 200, body: JSON.stringify(response.Items) } | ||
} catch (dbError) { | ||
return { statusCode: 500, body: JSON.stringify(dbError) }; | ||
return { statusCode: 500, body: JSON.stringify(dbError) } | ||
} | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb'; | ||
import { DynamoDB } from '@aws-sdk/client-dynamodb'; | ||
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb" | ||
import { DynamoDB } from "@aws-sdk/client-dynamodb" | ||
|
||
const TABLE_NAME = process.env.TABLE_NAME || ''; | ||
const PRIMARY_KEY = process.env.PRIMARY_KEY || ''; | ||
const TABLE_NAME = process.env.TABLE_NAME || "" | ||
const PRIMARY_KEY = process.env.PRIMARY_KEY || "" | ||
|
||
const db = DynamoDBDocument.from(new DynamoDB()); | ||
const db = DynamoDBDocument.from(new DynamoDB()) | ||
|
||
export const handler = async (event: any = {}): Promise<any> => { | ||
|
||
const requestedItemId = event.pathParameters.id; | ||
const requestedItemId = event.pathParameters.id | ||
if (!requestedItemId) { | ||
return { statusCode: 400, body: `Error: You are missing the path parameter id` }; | ||
return { | ||
statusCode: 400, | ||
body: `Error: You are missing the path parameter id`, | ||
} | ||
} | ||
|
||
const params = { | ||
TableName: TABLE_NAME, | ||
Key: { | ||
[PRIMARY_KEY]: requestedItemId | ||
} | ||
}; | ||
[PRIMARY_KEY]: requestedItemId, | ||
}, | ||
} | ||
|
||
try { | ||
const response = await db.get(params); | ||
const response = await db.get(params) | ||
if (response.Item) { | ||
return { statusCode: 200, body: JSON.stringify(response.Item) }; | ||
console.log("Retrieve Success; ", { | ||
statusCode: 200, | ||
body: JSON.stringify(response.Item), | ||
}) | ||
return { statusCode: 200, body: JSON.stringify(response.Item) } | ||
} else { | ||
return { statusCode: 404 }; | ||
return { statusCode: 404 } | ||
} | ||
} catch (dbError) { | ||
return { statusCode: 500, body: JSON.stringify(dbError) }; | ||
return { statusCode: 500, body: JSON.stringify(dbError) } | ||
} | ||
}; | ||
} |
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