![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@aws-solutions-constructs/aws-openapigateway-lambda
Advanced tools
CDK constructs for defining an interaction between an OpenAPI-defined API Gateway and one or more Lambda functions.
Reference Documentation: | https://docs.aws.amazon.com/solutions/latest/constructs/ |
---|
Language | Package |
---|---|
![]() | aws_solutions_constructs.aws_openapigateway_lambda |
![]() | @aws-solutions-constructs/aws-openapigateway-lambda |
![]() | software.amazon.awsconstructs.services.openapigatewaylambda |
This AWS Solutions Construct implements an Amazon API Gateway REST API defined by an OpenAPI specification file connected to an AWS Lambda function.
Here is a minimal deployable pattern definition:
Typescript
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { OpenApiApiGatewayToLambda } from './construct';
import { Asset } from 'aws-cdk-lib/aws-s3-assets';
import * as path from 'path';
import * as lambda from 'aws-cdk-lib/aws-lambda';
const apiDefinitionAsset = new Asset(this, 'ApiDefinitionAsset', {
path: path.join(__dirname, 'openapispec.yaml')
});
new OpenApiGatewayToLambda(this, 'OpenApiGatewayToLambda', {
apiDefinitionAsset,
apiIntegrations: [
{
id: 'MessagesHandler',
lambdaFunctionProps: {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(`${__dirname}/messages-lambda`),
}
}
]
});
Python
from aws_solutions_constructs.aws_openapigateway_lambda import ApiGatewayToLambda
from aws_cdk import (
Stack
)
import aws_cdk.aws_s3_assets as s3_assets
import aws_cdk.aws_lambda as lambda_
from constructs import Construct
from .api_definition import ApiDefinition
api_definition_asset = s3_assets.Asset(self, "ApiDefinitionAsset",
path="openapispec.yaml"
)
api_integration = ApiDefinition("MessagesHandler", (
runtime=lambda_.Runtime.NODEJS_18_X,
handler="index.handler",
code=lambda_.Code.from_inline("exports.handler = handler.toString()")
))
ApiGatewayToLambda(self, "OpenApiGatewayToLambda",
api_definition_asset = api_definition_asset,
api_integrations = [ api_integration]
)
Java
import software.amazon.awscdk.services.lambda.Code;
import software.amazon.awscdk.services.lambda.FunctionProps;
import software.amazon.awscdk.services.s3.assets.Asset;
import software.amazon.awscdk.services.s3.assets.AssetProps;
import software.amazon.awsconstructs.services.openapigatewaylambda.ApiIntegration;
import software.amazon.awsconstructs.services.openapigatewaylambda.OpenApiGatewayToLambda;
import software.amazon.awsconstructs.services.openapigatewaylambda.OpenApiGatewayToLambdaProps;
import software.constructs.Construct;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.StackProps;
import java.util.Collections;
import static software.amazon.awscdk.services.lambda.Runtime.NODEJS_18_X;
final Asset apiDefinitionAsset = new Asset(this, "ApiDefinition", AssetProps.builder().path("openapispec.yaml").build());
final ApiIntegration apiIntegration = ApiIntegration.builder()
.id("MessagesHandler")
.lambdaFunctionProps(new FunctionProps.Builder()
.runtime(NODEJS_18_X)
.code(Code.fromAsset("lambda"))
.handler("index.handler")
.build())
.build();
new OpenApiGatewayToLambda(this, "OpenApiGatewayToLambda", OpenApiGatewayToLambdaProps.builder()
.apiDefinitionAsset(apiDefinitionAsset)
.apiIntegrations(Collections.singletonList(apiIntegration))
.build());
Name | Type | Description |
---|---|---|
apiGatewayProps? | apigateway.RestApiBaseProps | Optional user-provided props to override the default props for the API. |
apiDefinitionBucket? | s3.IBucket | S3 Bucket where the OpenAPI spec file is located. When specifying this property, apiDefinitionKey must also be specified. |
apiDefinitionKey? | string | S3 Object name of the OpenAPI spec file. When specifying this property, apiDefinitionBucket must also be specified. |
apiDefinitionAsset? | aws_s3_assets.Asset | Local file asset of the OpenAPI spec file. |
apiIntegrations | ApiIntegration[] | One or more key-value pairs that contain an id for the api integration and either an existing lambda function or an instance of the LambdaProps. Please see the Overview of how the OpenAPI file transformation works section below for more usage details. |
logGroupProps? | logs.LogGroupProps | User provided props to override the default props for for the CloudWatchLogs LogGroup. |
Name | Type | Description |
---|---|---|
apiLambdaFunctions | ApiLambdaFunction[] | Returns an array of ApiLambdaFunction objects, where each has an id of the apiIntegration and the corresponding lambda.Function that it maps to. |
apiGateway | api.SpecRestApi | Returns an instance of the API Gateway REST API created by the pattern. |
apiGatewayCloudWatchRole? | iam.Role | Returns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access. |
apiGatewayLogGroup | logs.LogGroup | Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch. |
This construct automatically transforms an incoming OpenAPI Definition (residing locally or in S3) by auto-populating the uri
fields of the x-amazon-apigateway-integration
integrations with the resolved value of the backing lambda functions. It does so by allowing the user to specify the apiIntegrations
property and then correlates it with the api definition.
Looking at an example - a user creates an instantiation of apiIntegrations
that specifies one integration named MessagesHandler
that passes in a set of lambda.FunctionProps
and a second integration named PhotosHandler
that passes in an existing lambda.Function
:
const apiIntegrations: ApiIntegration[] = [
{
id: 'MessagesHandler',
lambdaFunctionProps: {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(`${__dirname}/messages-lambda`),
}
},
{
id: 'PhotosHandler',
existingLambdaObj: new lambda.Function(this, 'PhotosLambda', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(`${__dirname}/photos-lambda`),
})
}
]
And a corresponding api definition with GET
and POST
methods on a /messages
resource and a GET
method on a /photos
resource.
openapi: "3.0.1"
info:
title: "api"
version: "2023-02-20T20:46:08Z"
paths:
/messages:
get:
x-amazon-apigateway-integration:
httpMethod: "POST"
uri: MessagesHandler
passthroughBehavior: "when_no_match"
type: "aws_proxy"
post:
x-amazon-apigateway-integration:
httpMethod: "POST"
uri: MessagesHandler
passthroughBehavior: "when_no_match"
type: "aws_proxy"
/photos:
get:
x-amazon-apigateway-integration:
httpMethod: "POST"
uri: PhotosHandler
passthroughBehavior: "when_no_match"
type: "aws_proxy"
When the construct is created or updated, it will overwrite the MessagesHandler
string with the fully resolved lambda proxy uri of the MessagesHandlerLambdaFunction
, e.g., arn:${Aws.PARTITION}:apigateway:${Aws.REGION}:lambda:path/2015-03-31/functions/${messagesLambda.functionArn}/invocations
, and similarly for the PhotosHandler
string and PhotosHandlerLambdaFunction
, resulting in a valid OpenAPI spec file that is then passed to the SpecRestApi
construct.
For more information on specifying an API with OpenAPI, please see the OpenAPI Specification
This construct defines a custom type, ApiIntegration
, that is specified as a required prop. The type has a required property, id
, and two optional properties existingLambdaObj
and lambdaFunctionProps
. The id
property is used to map the corresponding lambda function being defined with the placeholder string in the OpenAPI template file, and is not a CDK construct ID. Exactly one of existingLambdaObj
or lambdaFunctionProps
must be specified or the construct will throw an error.
Out of the box implementation of the Construct without any override will set the following defaults:
© Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
FAQs
CDK constructs for defining an interaction between an OpenAPI-defined API Gateway and one or more Lambda functions.
The npm package @aws-solutions-constructs/aws-openapigateway-lambda receives a total of 0 weekly downloads. As such, @aws-solutions-constructs/aws-openapigateway-lambda popularity was classified as not popular.
We found that @aws-solutions-constructs/aws-openapigateway-lambda demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.