0

我刚刚尝试了Serverless的 .1.0.0-beta.1.1 版本,看起来很有希望。

我希望使用AWS_IAM.

我可以使用 AWS Gateway API 控制台,并将每个方法请求从 更改noneAWS_IAM. 用手,我可以让它工作。

但是,我宁愿更改serverless.yml无服务器服务中的文件。

我试图authorizationType像这样添加一个字段:

- http:
      path: greet
      method: get
      authorizationType: AWS_IAM

但它没有更新 API Gateway 的授权设置,仍然接受未经授权的请求。


知道serverless.yml文件是否可以设置为使用AWS_IAM

4

2 回答 2

2

在无服务器 1.0.0-RC2 中,您可以按如下方式设置授权类型

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get    

resources:
  Resources:
    ApiGatewayMethodHelloGet:
      Properties:
        AuthorizationType: AWS_IAM 
于 2016-10-11T15:18:17.420 回答
1

查看以下链接,了解我在身份验证帮助中找到的最接近的链接:

https://github.com/serverless/serverless/blob/85f4084e6b0fd4a6d763ace8cd0db82817bbc712/lib/plugins/aws/deploy/compile/events/apiGateway/README.md#http-setup-with-custom-authorizer

我没有使用 AWS_IAM,但这是我定义 CUSTOM 身份验证的方式,它应该指示整体格式。

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get
          authorizer:
            arn: arn:aws:lambda:us-east-1:xxxxxx:function:jwtAuthorize
            resultTtlInSeconds: 0
            identitySource: method.request.header.Authorization
            identityValidationExpression: JWT [^\.]+\.[^\.]+\.[^\.]+

因此,我认为您需要添加该authorizer部分。我无法对此进行测试,但如果它不能以这种方式工作,请告诉我:

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get
          authorizer:
            authorizationType: AWS_IAM
于 2016-08-25T15:54:23.173 回答