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 cdk from 'aws-cdk-lib'; | |
import { Construct } from 'constructs'; | |
import * as apigateway from 'aws-cdk-lib/aws-apigateway'; | |
export class MyStack extends cdk.Stack { | |
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
const api = new apigateway.RestApi(this, 'test-api', { | |
description: 'Test project', |
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
const storesTable = new Table(this, "stores-table", { | |
partitionKey: { name: "id", type: AttributeType.STRING }, | |
billingMode: BillingMode.PAY_PER_REQUEST, | |
tableClass: TableClass.STANDARD_INFREQUENT_ACCESS, | |
tableName: "stores", | |
removalPolicy: cdk.RemovalPolicy.DESTROY, | |
}); |
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'; | |
import { v4 as uuidv4 } from 'uuid'; | |
const TABLE_NAME = process.env.STORE_TABLE_NAME || ''; | |
const PRIMARY_KEY = process.env.STORE_PRIMARY_KEY || ''; | |
const db = new AWS.DynamoDB.DocumentClient(); | |
const RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attributes`, | |
DYNAMODB_EXECUTION_ERROR = `Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.`; | |
export const handler = async (event: any = {}): Promise<any> => { |
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) { |
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 db = new AWS.DynamoDB.DocumentClient(); | |
export const handler = async (event: any): Promise<any> => { | |
const params = { | |
TableName: TABLE_NAME, | |
}; |
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) { |
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 RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attributes`, | |
DYNAMODB_EXECUTION_ERROR = `Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.`; | |
const db = new AWS.DynamoDB.DocumentClient(); |
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
const nodejsProps: NodejsFunctionProps = { | |
depsLockFilePath: join(__dirname, '..', 'package-lock.json'), | |
environment: { | |
STORE_PRIMARY_KEY: 'id', // we're able to reference it in our lambda function with process.env | |
STORE_TABLE_NAME: storesTable.tableName, | |
} | |
}; | |
const getOneLambda = new NodejsFunction(this, 'getOneStoreFunction', { | |
entry: join(__dirname, '..', 'get-one.ts'), |
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
[createOneLambda, getAllLambda, getOneLambda, updateOneLambda, deleteOneLambda] | |
.forEach(i => storesTable.grantReadWriteData(i)); |
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
const getAllIntegration = new LambdaIntegration(getAllLambda, {proxy: true}); | |
const createOneIntegration = new LambdaIntegration(createOneLambda, {proxy: true}); | |
const getOneIntegration = new LambdaIntegration(getOneLambda, {proxy: true}); | |
const updateOneIntegration = new LambdaIntegration(updateOneLambda, {proxy: true}); | |
const deleteOneIntegration = new LambdaIntegration(deleteOneLambda, {proxy: true}); | |
const store = api.root.addResource('store'); | |
store.addMethod('POST', createOneIntegration); | |
store.addMethod('GET', getAllIntegration); |
OlderNewer