awslabs / aws-solutions-constructs

The AWS Solutions Constructs Library is an open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides multi-service, well-architected patterns for quickly defining solutions
https://docs.aws.amazon.com/solutions/latest/constructs/
Apache License 2.0
1.25k stars 249 forks source link

feat(aws-openapigateway-lambda): update construct to allow specifying an inline api definition #1190

Closed indieisaconcept closed 2 months ago

indieisaconcept commented 3 months ago

Issue #, if available:

Description of changes:

The rationale for this change is to improve the local developer experience and enable compatibility with sam local start-api. Previously, the construct only supported referencing an external OpenAPI definition file, which made it challenging to work with an API locally during development.

Example Usage

const isLocal = this.node.tryGetContext('api-local') as string | undefined;

const apiDefinition = isLocal ? {
  apiDefinitionInline: new InlineApiDefinition(definition)
} : {
  apiDefinitionAsset: new Asset(this, 'ApiDefinitionAsset', {
    path: path.join(__dirname, 'openapi/apiDefinition.yaml'),
  }),
};

new OpenApiGatewayToLambda(this, 'OpenApiGatewayToLambda', {
  ...apiDefinition,
  apiIntegrations: [
    {
      id: 'MessagesHandler',
      lambdaFunctionProps: {
        runtime: lambda.Runtime.NODEJS_18_X,
        handler: 'index.handler',
        code: lambda.Code.fromAsset(`${__dirname}/messages-lambda`),
      }
    }
  ]
});
aws-solutions-constructs-team commented 3 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

biffgaut commented 3 months ago

Thanks - we'll take a look!

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

aws-solutions-constructs-team commented 2 months ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository