How can i reuse an existing authorizer in a rest api through AWS CDK?

0

It seems there is no method to get an existing authorizer by its attributes, is there any other way?

1개 답변
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();
profile picture
전문가
답변함 2달 전

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

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

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

관련 콘텐츠