import * as cdk from '@aws-cdk/core' ; import lambda = require ( '@aws-cdk/aws-lambda' ) ; import apigw = require ( '@aws-cdk/aws-apigatewayv2' ) ; import integrations = require ( '@aws-cdk/aws-apigatewayv2-integrations' ) ; import iam = require ( '@aws-cdk/aws-iam' ) ; export class PollyStack extends cdk . Stack { constructor ( scope , id , props ? ) { super ( scope , id , props ) ; const pollyLambda = new lambda . Function ( this , 'PollyHandler' , { runtime : lambda . Runtime . NODEJS_12_X , code : lambda . Code . fromAsset ( 'lambda-fns' ) , handler : 'polly.handler' } ) ; const pollyStatement = new iam . PolicyStatement ( { effect : iam . Effect . ALLOW , resources : [ '*' ] , actions : [ "translate:TranslateText" , "polly:SynthesizeSpeech" ] , } ) ; pollyLambda . addToRolePolicy ( pollyStatement ) ; let api = new apigw . HttpApi ( this , 'Endpoint' , { defaultIntegration : new integrations . LambdaProxyIntegration ( { handler : pollyLambda } ) } ) ; new cdk . CfnOutput ( this , 'HTTP API Url' , { value : api . url ?? 'Something went wrong with the deploy' } ) ; } }