【问题标题】:Cannot deploy aws sam stack due to Handler not found error由于找不到处理程序错误,无法部署 aws sam 堆栈
【发布时间】:2019-04-20 19:30:01
【问题描述】:

我在使用 sam 在嵌套目录中部署带有处理程序的 lambda 时遇到问题。

我执行以下步骤:

  1. 包装:

    sam package --template template.yaml --output-template-file packaged.yaml --s3-bucket

创建我在下一步中使用的 packaged.yaml。

  1. 部署:

    aws cloudformation deploy --template-file /Users/localuser/Do/learn-sam/dynamo-stream-lambda/packaged.yaml --stack-name barkingstack

错误

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [PublishNewBark] is invalid. Missing required property 'Handler'.

Cloudformation/SAM 模板

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

Globals:
  Function:
    Runtime: nodejs8.10
    Timeout: 300

Resources:
  PublishNewBark:
    Type: AWS::Serverless::Function
    FunctionName: publishNewBark
    CodeUri: .
    Handler: src/index.handler
    Role: "<ROLE_ARN>"
    Description: Reads from the DynamoDB Stream and publishes to an SNS topic
    Events:
      - ReceiveBark:
          Type: DynamoDB
          Stream: !GetAtt BarkTable.StreamArn
          StartingPosition: TRIM_HORIZON
          BatchSize: 1


  BarkTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: BarkTable
      KeySchema:
        - KeyType: HASH
          AttributeName: id
      AttributeDefinitions:
        - AttributeName: id
          AttributeType: S
      StreamSpecification:
        StreamViewType: NEW_AND_OLD_IMAGES
      ProvisionedThroughput:
        WriteCapacityUnits: 5
        ReadCapacityUnits: 5

  WooferTopic:
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: wooferTopic
      TopicName: wooferTopic
      Subscription:
        - Endpoint: <my_email>
          Protocol: email

目录结构

根目录/ events/(用于示例事件) 策略/(用于使用 CLI 为 lambda 创建的 IAM 角色) src/index.js 包.json 节点模块 模板.yaml

处理程序代码

async function handler (event, context) {
  console.log(JSON.stringify(event, null, 2))
  return {}
}

module.exports = {handler}

【问题讨论】:

    标签: amazon-cloudformation aws-sam


    【解决方案1】:

    我相信您必须将除资源类型之外的所有内容都放在“属性”下。

    你的函数声明应该是:

    PublishNewBark:
        Type: AWS::Serverless::Function
        Properties:
            FunctionName: publishNewBark
            CodeUri: .
            Handler: src/index.handler
            Role: "<ROLE_ARN>"
            Description: Reads from the DynamoDB Stream and publishes to an SNS topic
            Events:
              - ReceiveBark:
                  Type: DynamoDB
                  Stream: !GetAtt BarkTable.StreamArn
                  StartingPosition: TRIM_HORIZON
                  BatchSize: 1
    

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 2021-05-04
      • 2020-06-26
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多