How to enable “ApiKeyRequired” property in SAM without explicit swagger definition?

廉价感情. 提交于 2019-12-04 04:43:06

问题


In cloudformation, AWS::ApiGateway::Method has a boolean property ApiKeyRequired . How can i achieve the same in SAM ?

I know that we can enable using explicit swagger Configuration. which is like this

    {
    "swagger": "2.0",
    "info": {
        "version": "1.0",
        "title": {
              "Ref": "AWS::StackName"
            }
    },
    "x-amazon-apigateway-api-key-source": "HEADER",
    "paths": {
        "/": {
            "get": {
                "x-amazon-apigateway-integration": {
                    "httpMethod": "POST",
                    "type": "aws_proxy",
                    "uri": {
                    "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHelloWorld.Arn}/invocations"
                  }
                },
                "responses": {},
                "security": [
                    {
                        "api_key": []
                    }
                ]
            }
        }
    },
    "securityDefinitions": {
        "api_key": {
            "type": "apiKey",
            "name": "x-api-key",
            "in": "header"
        }
    }
}

Cant it possible with implicit API call in SAM rather than explicitly passing the AWS::Serverless::Api ? Because the swagger code is okay for less endpoints and becomes complex once endpoints got increased. Is there any flag like APIkeyRequired like we have in Cloudformation ?

Any help is appreciated Thanks

来源:https://stackoverflow.com/questions/52936126/how-to-enable-apikeyrequired-property-in-sam-without-explicit-swagger-definiti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!