AWS API Gateway REST API是否没有设置来禁用CloudFormation模板中的execute-api终端节点?

马塞利·瓦克(Marceli Wac)

我已经使用CloudFormation模板设置了API网关(v1,而不是v2)REST API资源。最近,我注意到还创建了默认的execute-api端点,可以在设置中将其禁用。

在此处输入图片说明 该API的类型为AWS::ApiGateway::RestApi

Naturally, I would like this to be done through the template, so the question is: can this setting be defined in the CloudFormation template, rather than havign to be clicked manually in the AWS Console? This option is available for the APIGateway V2 API resource (AWS::ApiGatewayV2::Api) but not the APIGateway V1 REST API resource (AWS::ApiGateway::RestApi) in the CloudFormation templates, even though it can be changed manuall for the APIGateway V1 REST API in the console.

There is also a CLI way of doing this for the AWS::ApiGateway::RestApi.

Here are some links I have used to search for this setting:
AWS::ApiGatewayV2::API
AWS::ApiGateway::RestApi
Disabling default api-execute endpoint via CLI

Marcin

您可以通过简单的自定义资源禁用它下面是一个这样的完全有效的模板的示例,该模板可以执行以下操作:


Resources:

  MyRestApi:
    Type: 'AWS::ApiGateway::RestApi'
    Properties:
      Description: A test API
      Name: MyRestAPI


  LambdaBasicExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Effect: Allow
          Principal:
            Service: lambda.amazonaws.com
          Action: sts:AssumeRole
      Path: /
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AmazonAPIGatewayAdministrator
        - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

  MyCustomResource:
    Type: Custom::DisableDefaultApiEndpoint
    Properties:
      ServiceToken: !GetAtt 'MyCustomFunction.Arn'
      APIId: !Ref 'MyRestApi'

  MyCustomFunction:
    Type: AWS::Lambda::Function
    Properties:
      Handler: index.lambda_handler
      Description: "Disable default API endpoint"
      Timeout: 30
      Role: !GetAtt 'LambdaBasicExecutionRole.Arn'
      Runtime: python3.7
      Code:
        ZipFile: |
          import json
          import logging
          import cfnresponse
          import boto3
          
          logger = logging.getLogger()
          logger.setLevel(logging.INFO)

          client = boto3.client('apigateway')

          def lambda_handler(event, context):
            logger.info('got event {}'.format(event))  
            try:

              responseData = {}

              if event['RequestType'] in ["Create"]:                      
                
                APIId = event['ResourceProperties']['APIId']                
                
                response = client.update_rest_api(
                    restApiId=APIId,
                    patchOperations=[
                        {
                            'op': 'replace',
                            'path': '/disableExecuteApiEndpoint',
                            'value': 'True'
                        }
                    ]
                )

                logger.info(str(response))

                cfnresponse.send(event, context, 
                                 cfnresponse.SUCCESS, responseData)

              else:
                logger.info('Unexpected RequestType!') 
                cfnresponse.send(event, context, 
                                  cfnresponse.SUCCESS, responseData)

            except Exception as err:

              logger.error(err)
              responseData = {"Data": str(err)}
              cfnresponse.send(event,context, 
                               cfnresponse.FAILED,responseData)
            return              

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从AWS API Gateway获取终端节点/ URI?

来自分类Dev

重命名AWS Api Gateway中的终端节点并保持向后兼容性

来自分类Dev

如何使用自定义域创建SSL AWS API Gateway终端节点?

来自分类Dev

如何通过AWS API Gateway对单个终端节点使用多个Cognito用户池?

来自分类Dev

使用AWS Api Gateway终端节点设置HTTP代理时,您可以静态设置标头及其值吗?

来自分类Dev

在API网关终端节点之后本地测试AWS Lambda

来自分类Dev

我如何知道谁在向我的Amazon API Gateway终端节点发送请求?

来自分类Dev

将复杂类型传递给AWS API网关终端节点

来自分类Dev

AWS API网关错误,与终端节点通信的网络错误,504网关超时

来自分类Dev

从aws_api_gateway_rest_api迁移到aws_apigatewayv2_api松散的OpenAPI集成

来自分类Dev

从AWS API Gateway返回HTML

来自分类Dev

AWS Api Gateway与Dynamo的集成

来自分类Dev

带有AWS WAF的AWS API Gateway

来自分类Dev

从AWS API Gateway导出API定义

来自分类Dev

使用AWS Api Gateway进行Api合成

来自分类Dev

消耗AWS API Gateway API的问题

来自分类Dev

是否可以使用“ HTTP”协议(而非REST)通过AWS API Gateway返回HTML?

来自分类Dev

使用AWS cli将自定义域迁移到其他API终端节点时出现问题

来自分类Dev

AWS API Gateway:传递所有参数

来自分类Dev

捕获AWS Api Gateway中的超时错误

来自分类Dev

捕获AWS Api Gateway中的超时错误

来自分类Dev

如何访问AWS API Gateway的path参数?

来自分类Dev

如何为AWS API Gateway认证用户?

来自分类Dev

AWS API Gateway更改内容类型

来自分类Dev

使用API Gateway的AWS Lambda错误消息

来自分类Dev

AWS API Gateway:错误429请求太多

来自分类Dev

Haproxy授权来自AWS API Gateway的流量

来自分类Dev

AWS API Gateway + DynamoDB角色ARN错误

来自分类Dev

配置AWS API Gateway的日志记录

Related 相关文章

  1. 1

    如何从AWS API Gateway获取终端节点/ URI?

  2. 2

    重命名AWS Api Gateway中的终端节点并保持向后兼容性

  3. 3

    如何使用自定义域创建SSL AWS API Gateway终端节点?

  4. 4

    如何通过AWS API Gateway对单个终端节点使用多个Cognito用户池?

  5. 5

    使用AWS Api Gateway终端节点设置HTTP代理时,您可以静态设置标头及其值吗?

  6. 6

    在API网关终端节点之后本地测试AWS Lambda

  7. 7

    我如何知道谁在向我的Amazon API Gateway终端节点发送请求?

  8. 8

    将复杂类型传递给AWS API网关终端节点

  9. 9

    AWS API网关错误,与终端节点通信的网络错误,504网关超时

  10. 10

    从aws_api_gateway_rest_api迁移到aws_apigatewayv2_api松散的OpenAPI集成

  11. 11

    从AWS API Gateway返回HTML

  12. 12

    AWS Api Gateway与Dynamo的集成

  13. 13

    带有AWS WAF的AWS API Gateway

  14. 14

    从AWS API Gateway导出API定义

  15. 15

    使用AWS Api Gateway进行Api合成

  16. 16

    消耗AWS API Gateway API的问题

  17. 17

    是否可以使用“ HTTP”协议(而非REST)通过AWS API Gateway返回HTML?

  18. 18

    使用AWS cli将自定义域迁移到其他API终端节点时出现问题

  19. 19

    AWS API Gateway:传递所有参数

  20. 20

    捕获AWS Api Gateway中的超时错误

  21. 21

    捕获AWS Api Gateway中的超时错误

  22. 22

    如何访问AWS API Gateway的path参数?

  23. 23

    如何为AWS API Gateway认证用户?

  24. 24

    AWS API Gateway更改内容类型

  25. 25

    使用API Gateway的AWS Lambda错误消息

  26. 26

    AWS API Gateway:错误429请求太多

  27. 27

    Haproxy授权来自AWS API Gateway的流量

  28. 28

    AWS API Gateway + DynamoDB角色ARN错误

  29. 29

    配置AWS API Gateway的日志记录

热门标签

归档