Package: aws-solutions-constructs.aws-cloudfront-apigateway-lambda
aws-cloudfront-apigateway-lambda module---Reference Documentation:https://docs.aws.amazon.com/solutions/latest/constructs/LanguagePackagePythonaws_solutions_constructs.aws_cloudfront_apigateway_lambdaTypescript@aws-solutions-constructs/aws-cloudfront-apigateway-lambdaJavasoftware.amazon.awsconstructs.services.cloudfrontapigatewaylambdaOverviewThis AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway Lambda backed REST API.Here is a minimal deployable pattern definition:Typescriptimport{Construct}from'constructs';import{Stack,StackProps}from'aws-cdk-lib';import{CloudFrontToApiGatewayToLambda}from'@aws-solutions-constructs/aws-cloudfront-apigateway-lambda';import*aslambdafrom'aws-cdk-lib/aws-lambda';newCloudFrontToApiGatewayToLambda(this,'test-cloudfront-apigateway-lambda',{lambdaFunctionProps:{code:lambda.Code.fromAsset(`lambda`),runtime:lambda.Runtime.NODEJS_16_X,handler:'index.handler'},apiGatewayProps:{defaultMethodOptions:{authorizationType:api.AuthorizationType.NONE}},});Pythonfromaws_solutions_constructs.aws_cloudfront_apigateway_lambdaimportCloudFrontToApiGatewayToLambdafromaws_cdkimport(aws_lambdaas_lambda,aws_apigatewayasapigw,Stack)fromconstructsimportConstructCloudFrontToApiGatewayToLambda(self,'CloudFrontApiGatewayToLambda',lambda_function_props=_lambda.FunctionProps(runtime=_lambda.Runtime.PYTHON_3_7,code=_lambda.Code.from_asset('lambda'),handler='hello.handler',),# NOTE - we use RestApiProps here because the actual type, LambdaRestApiProps requires# the handler function which does not yet exist. As RestApiProps is a subset of of LambdaRestApiProps# (although does not *extend* that interface) this works fine when the props object reaches the# underlying TypeScript code that implements Constructsapi_gateway_props=apigw.RestApiProps(default_method_options=apigw.MethodOptions(authorization_type=apigw.AuthorizationType.NONE)))Javaimportsoftware.constructs.Construct;importsoftware.amazon.awscdk.Stack;importsoftware.amazon.awscdk.StackProps;importsoftware.amazon.awscdk.services.lambda.*;importsoftware.amazon.awscdk.services.lambda.Runtime;importsoftware.amazon.awsconstructs.services.cloudfrontapigatewaylambda.*;importsoftware.amazon.awsconstructs.services.cloudfrontapigatewaylambda.CloudFrontToApiGatewayToLambdaProps;newCloudFrontToApiGatewayToLambda(this,"ApiGatewayToLambdaPattern",newCloudFrontToApiGatewayToLambdaProps.Builder().lambdaFunctionProps(newFunctionProps.Builder().runtime(Runtime.NODEJS_16_X)// execution environment.code(Code.fromAsset("lambda"))// code loaded from the `lambda` directory (under root, next to `src`).handler("hello.handler")// file is `hello`, function is `handler`.build())// NOTE - we use RestApiProps here because the actual type, LambdaRestApiProps requires// the handler function which does not yet exist. As RestApiProps is a subset of of LambdaRestApiProps// (although does not *extend* that interface) this works fine when the props object reaches the// underlying TypeScript code that implements Constructs.apiGatewayProps(newRestApiProps.Builder().defaultMethodOptions(newMethodOptions.Builder().authorizationType(AuthorizationType.NONE).build()).build()).build());Pattern Construct PropsNameTypeDescriptionexistingLambdaObj?lambda.FunctionExisting instance of Lambda Function object, providing both this andlambdaFunctionPropswill cause an error.lambdaFunctionProps?lambda.FunctionPropsOptional user provided props to override the default props for the Lambda function.apiGatewayProps?api.LambdaRestApiPropsUser provided props to override the default props for the API Gateway. As of release 2.48.0, clients must include this property withdefaultMethodOptions: { authorizationType: string }specified. See Issue1043 in the github repohttps://github.com/awslabs/aws-solutions-constructs/issues/1043cloudFrontDistributionProps?cloudfront.DistributionPropsOptional user provided props to override the default props for CloudFront DistributioninsertHttpSecurityHeaders?booleanOptional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFrontresponseHeadersPolicyProps?cloudfront.ResponseHeadersPolicyPropsOptional user provided configuration that cloudfront applies to all http responses.logGroupProps?logs.LogGroupPropsOptional user provided props to override the default props for for the CloudWatchLogs LogGroup.cloudFrontLoggingBucketProps?s3.BucketPropsOptional user provided props to override the default props for the CloudFront Logging Bucket.Pattern PropertiesNameTypeDescriptioncloudFrontWebDistributioncloudfront.DistributionReturns an instance of cloudfront.Distribution created by the constructcloudFrontFunction?cloudfront.FunctionReturns an instance of the Cloudfront function created by the pattern.cloudFrontLoggingBuckets3.BucketReturns an instance of the logging bucket for CloudFront Distribution.apiGatewayapi.RestApiReturns an instance of the API Gateway REST API created by the pattern.apiGatewayCloudWatchRole?iam.RoleReturns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.apiGatewayLogGrouplogs.LogGroupReturns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.lambdaFunctionlambda.FunctionReturns an instance of the Lambda function created by the pattern.Default settingsOut of the box implementation of the Construct without any override will set the following defaults:Amazon CloudFrontConfigure Access logging for CloudFront DistributionEnable automatic injection of best practice HTTP security headers in all responses from CloudFront DistributionAmazon API GatewayDeploy a regional API endpointEnable CloudWatch logging for API GatewayConfigure least privilege access IAM role for API GatewaySet the default authorizationType for all API methods to NONEEnable X-Ray TracingAWS Lambda FunctionConfigure limited privilege access IAM role for Lambda functionEnable reusing connections with Keep-Alive for NodeJs Lambda functionEnable X-Ray TracingSet Environment VariablesAWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)Architecture© Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.