Skip to content

Instantly share code, notes, and snippets.

@tmclaugh

tmclaugh/ddb.ts Secret

Last active Feb 24, 2020
Embed
What would you like to do?
import { Handler, Context, APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
import DynamoDB = require('@aws-sdk/client-dynamodb');
const helloWorldTableName = process.env.DDB_TABLE_NAME as string;
const helloWorldTablePk = process.env.DDB_TABLE_PK as string;
const ddbClient = new DynamoDB.DynamoDBClient({});
const handler: Handler = async function(event: APIGatewayEvent, context: Context) {
const getItemParams: DynamoDB.GetItemCommandInput = {
TableName: helloWorldTableName,
Key: {
[helloWorldTablePk]: {
'S': 'foo'
}
}
};
const getItem = new DynamoDB.GetItemCommand(getItemParams);
const item = await ddbClient.send(getItem);
const resp: APIGatewayProxyResult = {
statusCode: 200,
body: JSON.stringify({'message': 'hello world'})
}
return resp;
}
export { handler }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment