1 réponse
- Le plus récent
- Le plus de votes
- La plupart des commentaires
0
In AWS CDK, you can reuse an existing authorizer in a REST API by referencing it using its ARN (Amazon Resource Name). Since there isn't a direct method to get an existing authorizer by its attributes, you would typically create an instance of CfnAuthorizer using its ARN. Here's how you can do it in typescript:
import * as cdk from '@aws-cdk/core';
import * as apigateway from '@aws-cdk/aws-apigateway';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');
// Assuming you have an existing authorizer ARN
const existingAuthorizerArn = 'arn:aws:apigateway:region::/restapis/api-id/authorizers/authorizer-id';
// Create a reference to the existing authorizer
const existingAuthorizer = apigateway.CfnAuthorizer.fromAuthorizerId(stack, 'ExistingAuthorizer', existingAuthorizerArn);
// Now you can use this existing authorizer in your API Gateway
const api = new apigateway.RestApi(stack, 'MyRestApi');
const resource = api.root.addResource('myresource');
resource.addMethod('GET', new apigateway.HttpIntegration('http://example.com'), {
authorizer: existingAuthorizer // Attach the existing authorizer
});
app.synth();
Contenus pertinents
- demandé il y a un an
- demandé il y a 2 mois
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a 7 mois
- AWS OFFICIELA mis à jour il y a 4 mois
I don't get it, the authorizer id is the arn? if we look at the doc https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.CfnAuthorizer.html there is nothing about using the arn. I'm using go btw.