适用于Visual Studio Code的AWS Toolkit无法识别有效的SAM模板

时间:2019-07-30 17:55:45

标签: visual-studio-code aws-lambda aws-sdk aws-sam

我已经安装了针对VSCode的新发布的AWS工具箱,希望通过我的lambda运行调试器(在node.js中实现)。我在插件中创建的lambda取得了成功,即代码镜头出现在app.js中。当我要调试现有的lambda函数时,会出现问题,即使它是有效的SAM模板,也不会出现代码镜头。我还可以通过“ sam --debug-port [...]”命令手动运行调试器,因此我知道问题出在插件上。

这是我的模板:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'SAM template for Serverless framework service: '
Resources:
  ApiGatewayAuthorizer:
    Type: 'AWS::ApiGateway::Authorizer'
    Properties:
      AuthorizerResultTtlInSeconds: 300
      IdentitySource: method.request.header.Authorization
      Name: my-authorizer
      RestApiId:
        Ref: ApiGatewayRestApi
      Type: COGNITO_USER_POOLS
      ProviderARNs:
        - >-
          arn:aws:cognito-idp:ca-central-1:xxx:userpool/ca-central-1_xxx
  DocumentDevList:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: handler.list
      Runtime: nodejs10.x
      CodeUri: app/
      MemorySize: 128
      Timeout: 15
      Policies:
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - 'ec2:CreateNetworkInterface'
                - 'ec2:DescribeNetworkInterfaces'
                - 'ec2:DeleteNetworkInterface'
              Resource: '*'
      Environment:
        Variables:
          DB_USERNAME: xxx
          DB_PASSWORD: xxx
          DB_NAME:
            xxx
          DB_HOST:
            127.0.0.1
      Events:
        Event1:
          Type: Api
          Properties:
            Path: '/entity/{entityId}/documents'
            Method: get
            RestApiId:
              Ref: Document
  Document:
    Type: 'AWS::Serverless::Api'
    Properties:
      StageName: dev
      DefinitionBody:
        swagger: '2.0'
        info:
          title:
            Ref: 'AWS::StackName'
        paths:
          '/entity/{entityId}/documents':
            options:
              x-amazon-apigateway-integration:
                type: mock
                requestTemplates:
                  application/json: '{ "statusCode" : 200 }'
                responses:
                  default:
                    statusCode: 200
                    responseParameters:
                      method.response.header.Access-Control-Allow-Headers: '''Content-Type,X-Amz-Date,Authorization,X-Api-Key'''
                      method.response.header.Access-Control-Allow-Methods: '''get'''
                      method.response.header.Access-Control-Allow-Origin: '''*'''
                    responseTemplates:
                      application/json: '{}'
              responses:
                '200':
                  headers:
                    Access-Control-Allow-Headers:
                      type: string
                    Access-Control-Allow-Methods:
                      type: string
                    Access-Control-Allow-Origin:
                      type: string
            get:
              x-amazon-apigateway-integration:
                httpMethod: POST
                type: aws_proxy
                uri:
                  'Fn::Sub': >-
                    arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DocumentDevList.Arn}/invocations
                responses:
                  default:
                    statusCode: 200
                    responseParameters:
                      method.response.header.Access-Control-Allow-Headers: '''Content-Type,X-Amz-Date,Authorization,X-Api-Key'''
                      method.response.header.Access-Control-Allow-Methods: '''get'''
                      method.response.header.Access-Control-Allow-Origin: '''*'''
                    responseTemplates:
                      application/json: '{}'
              responses:
                '200':
                  headers:
                    Access-Control-Allow-Headers:
                      type: string
                    Access-Control-Allow-Methods:
                      type: string
                    Access-Control-Allow-Origin:
                      type: string
  DocumentDevListLambdaPermission:
    Type: 'AWS::Lambda::Permission'
    DependsOn:
      - DocumentDevList
    Properties:
      Action: 'lambda:InvokeFunction'
      FunctionName:
        Ref: DocumentDevList
      Principal: apigateway.amazonaws.com

按照文档中的建议,我还单击了.js文件中的“ aws”标签。

希望有人能成功做到这一点。

-Esko

0 个答案:

没有答案