Skip to content

Instantly share code, notes, and snippets.

@shah-smit
Created September 15, 2021 16:34
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 shah-smit/3934d1a14c4b2e3af53c3e82215e3665 to your computer and use it in GitHub Desktop.
Save shah-smit/3934d1a14c4b2e3af53c3e82215e3665 to your computer and use it in GitHub Desktop.
Episode 2: CloudFormation and AWS CDK
import * as apigw from '@aws-cdk/aws-apigateway';
import * as lambda from '@aws-cdk/aws-lambda';
import { CfnOutput, Construct, Stack, StackProps } from '@aws-cdk/core';
import dynamodb = require('@aws-cdk/aws-dynamodb');
import * as path from 'path';
import * as cdk from '@aws-cdk/core';
export class CdkCloudFormationAppreciationDashboardStack extends cdk.Stack {
public readonly urlOutput: CfnOutput;
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const table = new dynamodb.Table(this, 'Messages', {
partitionKey: { name: 'messsage', type: dynamodb.AttributeType.STRING },
removalPolicy: cdk.RemovalPolicy.DESTROY
});
new cdk.CfnOutput(this, 'ddbTable', { value: table.tableName });
// The Lambda function that contains the functionality
const readHandler = new lambda.Function(this, 'ReadLambda', {
runtime: lambda.Runtime.PYTHON_3_8,
handler: 'index.lambda_handler',
code: lambda.Code.fromAsset(path.resolve(__dirname, 'read-lambda')),
environment: {
"TABLE": table.tableName
}
});
table.grantFullAccess(readHandler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment