Created
September 15, 2021 16:34
-
-
Save shah-smit/3934d1a14c4b2e3af53c3e82215e3665 to your computer and use it in GitHub Desktop.
Episode 2: CloudFormation and AWS CDK
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 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