# aws-cloudfront-apigateway-lambda module
<!--BEGIN STABILITY BANNER-->---
![Stability: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)
---
<!--END STABILITY BANNER-->
| **Reference Documentation**:| <span style="font-weight: normal">https://docs.aws.amazon.com/solutions/latest/constructs/</span>|
|:-------------|:-------------|
<div style="height:8px"></div>
| **Language** | **Package** |
|:-------------|-----------------|
|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cloudfront_apigateway_lambda`|
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-cloudfront-apigateway-lambda`|
|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cloudfrontapigatewaylambda`|
## Overview
This AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway Lambda backed REST API.
Here is a minimal deployable pattern definition:
Typescript
```python
import { Construct } from 'constructs';
import { Stack, StackProps } from 'aws-cdk-lib';
import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
new CloudFrontToApiGatewayToLambda(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
}
},
});
```
Python
```python
from aws_solutions_constructs.aws_cloudfront_apigateway_lambda import CloudFrontToApiGatewayToLambda
from aws_cdk import (
aws_lambda as _lambda,
aws_apigateway as apigw,
Stack
)
from constructs import Construct
CloudFrontToApiGatewayToLambda(
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 Constructs
api_gateway_props=apigw.RestApiProps(
default_method_options=apigw.MethodOptions(
authorization_type=apigw.AuthorizationType.NONE
)
)
)
```
Java
```java
import software.constructs.Construct;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.StackProps;
import software.amazon.awscdk.services.lambda.*;
import software.amazon.awscdk.services.lambda.Runtime;
import software.amazon.awsconstructs.services.cloudfrontapigatewaylambda.*;
import software.amazon.awsconstructs.services.cloudfrontapigatewaylambda.CloudFrontToApiGatewayToLambdaProps;
new CloudFrontToApiGatewayToLambda(this, "ApiGatewayToLambdaPattern", new CloudFrontToApiGatewayToLambdaProps.Builder()
.lambdaFunctionProps(new FunctionProps.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(new RestApiProps.Builder()
.defaultMethodOptions(new MethodOptions.Builder()
.authorizationType(AuthorizationType.NONE)
.build())
.build())
.build());
```
## Pattern Construct Props
| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html)|Existing instance of Lambda Function object, providing both this and `lambdaFunctionProps` will cause an error.|
|lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.FunctionProps.html)|Optional user provided props to override the default props for the Lambda function.|
|apiGatewayProps?|[`api.LambdaRestApiProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.LambdaRestApiProps.html)|User provided props to override the default props for the API Gateway. As of release 2.48.0, clients must include this property with `defaultMethodOptions: { authorizationType: string }` specified. See Issue1043 in the github repo https://github.com/awslabs/aws-solutions-constructs/issues/1043 |
|cloudFrontDistributionProps?|[`cloudfront.DistributionProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.DistributionProps.html)|Optional user provided props to override the default props for CloudFront Distribution|
|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFront|
| responseHeadersPolicyProps? | [`cloudfront.ResponseHeadersPolicyProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.ResponseHeadersPolicyProps.html) | Optional user provided configuration that cloudfront applies to all http responses. |
|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroupProps.html)|Optional user provided props to override the default props for for the CloudWatchLogs LogGroup.|
|cloudFrontLoggingBucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html)|Optional user provided props to override the default props for the CloudFront Logging Bucket.|
## Pattern Properties
| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|cloudFrontWebDistribution|[`cloudfront.Distribution`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.Distribution.html)|Returns an instance of cloudfront.Distribution created by the construct|
|cloudFrontFunction?|[`cloudfront.Function`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.Function.html)|Returns an instance of the Cloudfront function created by the pattern.|
|cloudFrontLoggingBucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-s3-readme.html)|Returns an instance of the logging bucket for CloudFront Distribution.|
|apiGateway|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html)|Returns an instance of the API Gateway REST API created by the pattern.|
|apiGatewayCloudWatchRole?|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.Role.html)|Returns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.|
|apiGatewayLogGroup|[`logs.LogGroup`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.|
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html)|Returns an instance of the Lambda function created by the pattern.|
## Default settings
Out of the box implementation of the Construct without any override will set the following defaults:
### Amazon CloudFront
* Configure Access logging for CloudFront Distribution
* Enable automatic injection of best practice HTTP security headers in all responses from CloudFront Distribution
### Amazon API Gateway
* Deploy a regional API endpoint
* Enable CloudWatch logging for API Gateway
* Configure least privilege access IAM role for API Gateway
* Set the default authorizationType for all API methods to NONE
* Enable X-Ray Tracing
### AWS Lambda Function
* Configure limited privilege access IAM role for Lambda function
* Enable reusing connections with Keep-Alive for NodeJs Lambda function
* Enable X-Ray Tracing
* Set Environment Variables
* AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)
## Architecture
![Architecture Diagram](architecture.png)
---
© Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Raw data
{
"_id": null,
"home_page": "https://github.com/awslabs/aws-solutions-constructs.git",
"name": "aws-solutions-constructs.aws-cloudfront-apigateway-lambda",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Amazon Web Services",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/21/d6/df888742744bfa884157117f8b918f428b968b957a28c7bc1662a0125218/aws_solutions_constructs_aws_cloudfront_apigateway_lambda-2.74.0.tar.gz",
"platform": null,
"description": "# aws-cloudfront-apigateway-lambda module\n\n<!--BEGIN STABILITY BANNER-->---\n\n\n![Stability: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)\n\n---\n<!--END STABILITY BANNER-->\n\n| **Reference Documentation**:| <span style=\"font-weight: normal\">https://docs.aws.amazon.com/solutions/latest/constructs/</span>|\n|:-------------|:-------------|\n\n<div style=\"height:8px\"></div>\n\n| **Language** | **Package** |\n|:-------------|-----------------|\n|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cloudfront_apigateway_lambda`|\n|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-cloudfront-apigateway-lambda`|\n|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cloudfrontapigatewaylambda`|\n\n## Overview\n\nThis AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway Lambda backed REST API.\n\nHere is a minimal deployable pattern definition:\n\nTypescript\n\n```python\nimport { Construct } from 'constructs';\nimport { Stack, StackProps } from 'aws-cdk-lib';\nimport { CloudFrontToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda';\nimport * as lambda from 'aws-cdk-lib/aws-lambda';\n\nnew CloudFrontToApiGatewayToLambda(this, 'test-cloudfront-apigateway-lambda', {\n lambdaFunctionProps: {\n code: lambda.Code.fromAsset(`lambda`),\n runtime: lambda.Runtime.NODEJS_16_X,\n handler: 'index.handler'\n },\n apiGatewayProps: {\n defaultMethodOptions: {\n authorizationType: api.AuthorizationType.NONE\n }\n },\n});\n```\n\nPython\n\n```python\nfrom aws_solutions_constructs.aws_cloudfront_apigateway_lambda import CloudFrontToApiGatewayToLambda\nfrom aws_cdk import (\n aws_lambda as _lambda,\n aws_apigateway as apigw,\n Stack\n)\nfrom constructs import Construct\n\n CloudFrontToApiGatewayToLambda(\n self, 'CloudFrontApiGatewayToLambda',\n lambda_function_props=_lambda.FunctionProps(\n runtime=_lambda.Runtime.PYTHON_3_7,\n code=_lambda.Code.from_asset('lambda'),\n handler='hello.handler',\n ),\n # NOTE - we use RestApiProps here because the actual type, LambdaRestApiProps requires\n # the handler function which does not yet exist. As RestApiProps is a subset of of LambdaRestApiProps\n # (although does not *extend* that interface) this works fine when the props object reaches the\n # underlying TypeScript code that implements Constructs\n api_gateway_props=apigw.RestApiProps(\n default_method_options=apigw.MethodOptions(\n authorization_type=apigw.AuthorizationType.NONE\n )\n )\n )\n```\n\nJava\n\n```java\nimport software.constructs.Construct;\n\nimport software.amazon.awscdk.Stack;\nimport software.amazon.awscdk.StackProps;\nimport software.amazon.awscdk.services.lambda.*;\nimport software.amazon.awscdk.services.lambda.Runtime;\nimport software.amazon.awsconstructs.services.cloudfrontapigatewaylambda.*;\nimport software.amazon.awsconstructs.services.cloudfrontapigatewaylambda.CloudFrontToApiGatewayToLambdaProps;\n\nnew CloudFrontToApiGatewayToLambda(this, \"ApiGatewayToLambdaPattern\", new CloudFrontToApiGatewayToLambdaProps.Builder()\n .lambdaFunctionProps(new FunctionProps.Builder()\n .runtime(Runtime.NODEJS_16_X) // execution environment\n .code(Code.fromAsset(\"lambda\")) // code loaded from the `lambda` directory (under root, next to `src`)\n .handler(\"hello.handler\") // file is `hello`, function is `handler`\n .build())\n // NOTE - we use RestApiProps here because the actual type, LambdaRestApiProps requires\n // the handler function which does not yet exist. As RestApiProps is a subset of of LambdaRestApiProps\n // (although does not *extend* that interface) this works fine when the props object reaches the\n // underlying TypeScript code that implements Constructs\n .apiGatewayProps(new RestApiProps.Builder()\n .defaultMethodOptions(new MethodOptions.Builder()\n .authorizationType(AuthorizationType.NONE)\n .build())\n .build())\n .build());\n```\n\n## Pattern Construct Props\n\n| **Name** | **Type** | **Description** |\n|:-------------|:----------------|-----------------|\n|existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html)|Existing instance of Lambda Function object, providing both this and `lambdaFunctionProps` will cause an error.|\n|lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.FunctionProps.html)|Optional user provided props to override the default props for the Lambda function.|\n|apiGatewayProps?|[`api.LambdaRestApiProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.LambdaRestApiProps.html)|User provided props to override the default props for the API Gateway. As of release 2.48.0, clients must include this property with `defaultMethodOptions: { authorizationType: string }` specified. See Issue1043 in the github repo https://github.com/awslabs/aws-solutions-constructs/issues/1043 |\n|cloudFrontDistributionProps?|[`cloudfront.DistributionProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.DistributionProps.html)|Optional user provided props to override the default props for CloudFront Distribution|\n|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFront|\n| responseHeadersPolicyProps? | [`cloudfront.ResponseHeadersPolicyProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.ResponseHeadersPolicyProps.html) | Optional user provided configuration that cloudfront applies to all http responses. |\n|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroupProps.html)|Optional user provided props to override the default props for for the CloudWatchLogs LogGroup.|\n|cloudFrontLoggingBucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html)|Optional user provided props to override the default props for the CloudFront Logging Bucket.|\n\n## Pattern Properties\n\n| **Name** | **Type** | **Description** |\n|:-------------|:----------------|-----------------|\n|cloudFrontWebDistribution|[`cloudfront.Distribution`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.Distribution.html)|Returns an instance of cloudfront.Distribution created by the construct|\n|cloudFrontFunction?|[`cloudfront.Function`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.Function.html)|Returns an instance of the Cloudfront function created by the pattern.|\n|cloudFrontLoggingBucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-s3-readme.html)|Returns an instance of the logging bucket for CloudFront Distribution.|\n|apiGateway|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html)|Returns an instance of the API Gateway REST API created by the pattern.|\n|apiGatewayCloudWatchRole?|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.Role.html)|Returns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.|\n|apiGatewayLogGroup|[`logs.LogGroup`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.|\n|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html)|Returns an instance of the Lambda function created by the pattern.|\n\n## Default settings\n\nOut of the box implementation of the Construct without any override will set the following defaults:\n\n### Amazon CloudFront\n\n* Configure Access logging for CloudFront Distribution\n* Enable automatic injection of best practice HTTP security headers in all responses from CloudFront Distribution\n\n### Amazon API Gateway\n\n* Deploy a regional API endpoint\n* Enable CloudWatch logging for API Gateway\n* Configure least privilege access IAM role for API Gateway\n* Set the default authorizationType for all API methods to NONE\n* Enable X-Ray Tracing\n\n### AWS Lambda Function\n\n* Configure limited privilege access IAM role for Lambda function\n* Enable reusing connections with Keep-Alive for NodeJs Lambda function\n* Enable X-Ray Tracing\n* Set Environment Variables\n\n * AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)\n\n## Architecture\n\n![Architecture Diagram](architecture.png)\n\n---\n\n\n\u00a9 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "CDK Constructs for AWS Cloudfront to AWS API Gateway to AWS Lambda integration.",
"version": "2.74.0",
"project_urls": {
"Homepage": "https://github.com/awslabs/aws-solutions-constructs.git",
"Source": "https://github.com/awslabs/aws-solutions-constructs.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0ef77e53d7be61fbf5cbbf368f5614c61305e03ebe868aa834d7a5d0d0cceb3c",
"md5": "aaf8d789d68d3854492e88db519b634f",
"sha256": "798c755540e2eea592b445fd519f151eb3e6a233117a2f918e4b10103a64be70"
},
"downloads": -1,
"filename": "aws_solutions_constructs.aws_cloudfront_apigateway_lambda-2.74.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aaf8d789d68d3854492e88db519b634f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.8",
"size": 216537,
"upload_time": "2024-10-22T18:07:20",
"upload_time_iso_8601": "2024-10-22T18:07:20.833630Z",
"url": "https://files.pythonhosted.org/packages/0e/f7/7e53d7be61fbf5cbbf368f5614c61305e03ebe868aa834d7a5d0d0cceb3c/aws_solutions_constructs.aws_cloudfront_apigateway_lambda-2.74.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "21d6df888742744bfa884157117f8b918f428b968b957a28c7bc1662a0125218",
"md5": "ecbb227706d060add51e8bd67d32a818",
"sha256": "4a55964f795dfb67c1fe3c41c8fd60891bfe7227fccfd9844aa20bd0e518d251"
},
"downloads": -1,
"filename": "aws_solutions_constructs_aws_cloudfront_apigateway_lambda-2.74.0.tar.gz",
"has_sig": false,
"md5_digest": "ecbb227706d060add51e8bd67d32a818",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.8",
"size": 217868,
"upload_time": "2024-10-22T18:09:10",
"upload_time_iso_8601": "2024-10-22T18:09:10.687870Z",
"url": "https://files.pythonhosted.org/packages/21/d6/df888742744bfa884157117f8b918f428b968b957a28c7bc1662a0125218/aws_solutions_constructs_aws_cloudfront_apigateway_lambda-2.74.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-22 18:09:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "awslabs",
"github_project": "aws-solutions-constructs",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aws-solutions-constructs.aws-cloudfront-apigateway-lambda"
}