¿Cómo migrar de apigateway a apigatewayv2 usando AWS-CDK?
Específicamente: estoy usando LambdaRestApi y restApiId y deploymentStage de ese recurso.
// old const apiGw = new apigateway.LambdaRestApi(this, 'MyAPI', { handler: lambdaFrontend, proxy: true, binaryMediaTypes: ['*/*'], }); // new const apiGw2 = new apigateway.CfnApi(this as any, 'MyAPIV2', { protocolType: "http", target: lambdaFrontend.functionArn, }) Estoy tratando de obtener OriginSource para CF así: const domainName = ${apiGw.restApiId}.execute-api.${this.region}.${this.urlSuffix};
Primera pregunta: ¿Cómo puedo recuperar el nombre de dominio con domainName ?
También necesito el nombre del escenario. Actualmente lo estoy recuperando así: const originPath = '/' + apiGw.deploymentStage.stageName;
Segunda pregunta: ¿Cómo puedo recuperar la ruta de origen con ApiGW2?
Alternativamente: ¿hay una mejor manera de conectar mi ApiGW2 con CF?
const fecf = new cf.CloudFrontWebDistribution(this, "MyCF", { originConfigs: [{ customOriginSource: { domainName: `${apiGw.restApiId}.execute-api.${this.region}.${this.urlSuffix}`, }, originPath: '/' + apiGw.deploymentStage.stageName, ... }Esto ahora se puede resolver con bastante facilidad ya que ahora tenemos documentación oficial para esto. Si alguien quiere migrar a V2 ahora, esta es la forma:
const httpApiIntegration = new apigatewayv2Integrations.LambdaProxyIntegration({ handler: fn, }); const httpApi = new apigatewayv2.HttpApi(this, "MyApiV2"); httpApi.addRoutes({ path: "/", methods: [HttpMethod.ANY], integration: httpApiIntegration, }); new cloudfront.CloudFrontWebDistribution(this, "MyCf", { defaultRootObject: "/", originConfigs: [ { customOriginSource: { domainName: `${httpApi.httpApiId}.execute-api.${this.region}.${this.urlSuffix}`, }, behaviors: [ { isDefaultBehavior: true, }, ], }, ], enableIpV6: true, });https://docs.aws.amazon.com/cdk/api/latest/docs/aws-apigatewayv2-readme.html
Pasos: