AWS SAM cloudformation:API网关无法调用lambda(AWS :: Serverless :: Function)

时间:2018-09-10 19:19:38

标签: aws-lambda amazon-cloudformation aws-api-gateway aws-sam

我创建了一个template.yaml文件来声明一个简单的由api网关调用的lambda函数。当我尝试从api网关url调用该函数时,请求失败,并显示{"message": "Internal server error"},并且在cloudwatch api网关日志中,我看到错误消息对Lambda函数的无效权限

这是我的template.yaml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
    AliasName:
        Type: String
        Default: dev

Resources:
    DynamoDBTenantTable:
        Type: AWS::DynamoDB::Table
        Properties:
            AttributeDefinitions:
                - AttributeName: clientApiKey
                  AttributeType: S
            KeySchema:
                - AttributeName: clientApiKey
                  KeyType: HASH
            ProvisionedThroughput:
                ReadCapacityUnits: 5
                WriteCapacityUnits: 5
            TableName: !Sub "authtable-${AliasName}"


    AmeAuthenticatorLambda:
        Type: AWS::Serverless::Function
        Properties:
            Handler: authenticator.handler
            Policies: AmazonDynamoDBFullAccess
            Runtime: nodejs8.10
            CodeUri: src/
            Environment:
                Variables:
                    TABLE_NAME: !Sub "authtable-${AliasName}"
            Events:
                AuthenticatorEvent:
                    Type: Api
                    Properties:
                        Path: /authentication/
                        Method: POST

SAM文档说上述语法可以create the necessary permissions and API declaration implicitly

我还遵循了AWS website中的一个示例。

如果我将 lambda:InvokeFunction 权限添加到template.yaml文件,则该调用有效,但是通过阅读文档可以做到这一点。

怎么可能出问题了?

0 个答案:

没有答案