Skip to content

Instantly share code, notes, and snippets.

View AndrewBestbier's full-sized avatar

Andrew AndrewBestbier

  • McKinsey & Company
  • London
View GitHub Profile
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async event => {
const params = {
TableName: "books" // The name of your DynamoDB table
};
try {
// Utilising the scan method to get all items in the table
const data = await documentClient.scan(params).promise();
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async event => {
const {
pathParameters: { id }
} = event; // Extracting an id from the request path
const params = {
TableName: "books", // The name of your DynamoDB table
Key: { id } // They key of the item you wish to find.
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async event => {
const {
pathParameters: { id }
} = event;
const params = {
TableName: "books",
Key: { id }
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async event => {
const {
pathParameters: { id }
} = event;
const { title } = JSON.parse(event.body);
const params = {
TableName: "books",
AWSTemplateFormatVersion: "2010-09-09" # (1)
Transform: AWS::Serverless-2016-10-31 # (1)
Resources: # (2)
DynamoBooksTable: # (3)
Type: AWS::Serverless::SimpleTable # (4)
Properties:
TableName: books # (5)
PrimaryKey:
Name: id # (6)
Type: String
AWSTemplateFormatVersion: "2010-09-09" # (1)
Transform: AWS::Serverless-2016-10-31 # (1)
Resources: # (2)
DynamoBooksTable: # (3)
Type: AWS::Serverless::SimpleTable # (4)
Properties:
TableName: books # Naming our table
PrimaryKey:
Name: id # Setting the primary key of each item in our database as id
Type: String
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
DynamoBooksTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: books
PrimaryKey:
Name: id
Type: String
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
DynamoBooksTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: books
PrimaryKey:
Name: id
Type: String
AWSTemplateFormatVersion: 2010-09-09 # (1)
Resources: # (2)
VPC: # (3)
Type: AWS::EC2::VPC # (4)
Properties:
CidrBlock: 10.0.0.0/16 # (5)
PublicSubnetA: # (1)
Type: AWS::EC2::Subnet # (2)
Properties:
VpcId: !Ref VPC # (3)
CidrBlock: 10.0.0.0/24 # (4)
AvailabilityZone: !Select [0, !GetAZs ] # (5)
PublicSubnetB:
Type: AWS::EC2::Subnet
Properties: