CDK API gateway integration with VPC Link.

0

Hi, I have an API that I want to integrate with VPC link. In the aws document, we have found MockIntegration, LambdaIntegration, AwsIntegration and HttpIntegration. I don't see the VPC link integration. I have all the required parameters. Is there any way to integrate VPC link? Please suggest with your valuable information. Thanks. CDK VPC Link integration

2개 답변
0
수락된 답변

Have you tried the official document, or is something missing there? https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.VpcLink.html

profile picture
전문가
답변함 10달 전
  • This doc is mentioning IntegrationType as HTTP_PROXY, but in our case looking for IntegrationType as VpCLink

0

To integrate an API with a VPC Link using the AWS CDK (Cloud Development Kit), you can use the AwsIntegration class. The AwsIntegration class allows you to configure an integration with various AWS services, including VPC Links. Here's an example of how you can integrate your API with a VPC Link using CDK:

import * as cdk from 'aws-cdk-lib';
import { RestApi, AwsIntegration } from 'aws-cdk-lib/aws-apigateway';
import { VpcLink } from 'aws-cdk-lib/aws-apigatewayv2';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');

// Create the VPC Link
const vpcLink = new VpcLink(stack, 'MyVpcLink', {
  targets: [/* Specify your VPC endpoints or NLBs here */],
});

// Create the API Gateway RestApi
const api = new RestApi(stack, 'MyApi');

// Create the integration with the VPC Link
const integration = new AwsIntegration({
  service: 'your-service', // Replace with the service name you want to integrate with
  vpcLink,
});

// Create a resource and add a method with the VPC Link integration
const resource = api.root.addResource('my-resource');
resource.addMethod('GET', integration);

app.synth();

In the above code, you create a VPC Link using the VpcLink class, specifying the targets (such as VPC endpoints or NLBs) that you want to integrate with. Then, you create the API Gateway RestApi and the AwsIntegration with the desired service name and the VPC Link. Finally, you create a resource and add a method to the resource with the VPC Link integration.

Make sure to replace 'your-service' with the actual service name you want to integrate with (e.g., 's3' for Amazon S3).

This example demonstrates how to integrate a VPC Link with an API using the AWS CDK. Ensure that you have the necessary dependencies installed and adapt the code to your specific use case and CDK setup.

Dan
답변함 10달 전
  • Is there any option to add Endpoint Url? In the attached photo you can see this option Endpoint Url. How I can add this?

  • above code will not work as vpcLink is not a property of AwsIntegrationProps

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인