import { CfnOutput , Construct , Duration , RemovalPolicy , Stack , StackProps } from '@aws-cdk/core' ; import { Table , BillingMode , AttributeType } from '@aws-cdk/aws-dynamodb' ; import { NodejsFunction } from '@aws-cdk/aws-lambda-nodejs' ; import { Runtime } from '@aws-cdk/aws-lambda' ; import path = require ( 'path' ) ; export class CdkStack extends Stack { constructor ( scope , id , props ? ) { super ( scope , id , props ) ; const dynamoTable = new Table ( this , 'DynamoTable' , { partitionKey : { name : 'ID' , type : AttributeType . STRING } , billingMode : BillingMode . PAY_PER_REQUEST , removalPolicy : RemovalPolicy . DESTROY } ) ; const lambdaPutDynamoDB = new NodejsFunction ( this , 'lambdaPutDynamoDBHandler' , { runtime : Runtime . NODEJS_12_X , memorySize : 1024 , timeout : Duration . seconds ( 3 ) , entry : path . join ( __dirname , '../src/app.ts' ) , handler : 'main' , environment : { DatabaseTable : dynamoTable . tableName } } ) ; dynamoTable . grantWriteData ( lambdaPutDynamoDB ) ; new CfnOutput ( this , 'DynamoDbTableName' , { value : dynamoTable . tableName } ) ; new CfnOutput ( this , 'LambdFunctionArn' , { value : lambdaPutDynamoDB . functionArn } ) ; } }