import * as cdk from '@aws-cdk/core' ; import lambda = require ( '@aws-cdk/aws-lambda' ) ; import dynamodb = require ( '@aws-cdk/aws-dynamodb' ) ; import apigw = require ( '@aws-cdk/aws-apigatewayv2' ) ; import integrations = require ( '@aws-cdk/aws-apigatewayv2-integrations' ) ; export class TheSimpleWebserviceStack extends cdk . Stack { constructor ( scope , id , props ? ) { super ( scope , id , props ) ; const table = new dynamodb . Table ( this , 'Hits' , { partitionKey : { name : 'path' , type : dynamodb . AttributeType . STRING } } ) ; const dynamoLambda = new lambda . Function ( this , 'DynamoLambdaHandler' , { runtime : lambda . Runtime . NODEJS_12_X , code : lambda . Code . fromAsset ( 'lambda-fns' ) , handler : 'lambda.handler' , environment : { HITS_TABLE_NAME : table . tableName } } ) ; table . grantReadWriteData ( dynamoLambda ) ; let api = new apigw . HttpApi ( this , 'Endpoint' , { defaultIntegration : new integrations . LambdaProxyIntegration ( { handler : dynamoLambda } ) } ) ; new cdk . CfnOutput ( this , 'HTTP API Url' , { value : api . url ?? 'Something went wrong with the deploy' } ) ; } }