Skip to content

Instantly share code, notes, and snippets.

@tmclaugh

tmclaugh/ddb.ts Secret

Last active February 24, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmclaugh/0d4f4838d909e0e0e623194b7e3f50e6 to your computer and use it in GitHub Desktop.
Save tmclaugh/0d4f4838d909e0e0e623194b7e3f50e6 to your computer and use it in GitHub Desktop.
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