amazon-web-services - AWS S3创建错误: "The event is not supported for notifications (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument"

标签 amazon-web-services amazon-s3 aws-cloudformation serverless-application-model


我正在 Code9 中开发我的第一个 lambda,它应该由 S3 事件触发。不幸的是,当我尝试部署时,我不断收到 CloudFormation 错误:

"The event is not supported for notifications (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: CF3108325F3C9B60; S3 Extended Request ID: wcWzRXUu7YJn/BVnPDtOx7yBHllhIPELEwsTweqVcfwLw1hkR2iDiSmQbxeL3Hrtp7Kv58ujS2s=; Proxy: null)"


请参阅以下来自 AWS Mgm 控制台的 CloudFormation 事件:

enter image description here

下面是我的 AWS SAM template.yaml 文件:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
  olatexOrdersInputDirectory:
    Type: 'AWS::S3::Bucket'
  olatexXlsxOrderLoader:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: olatexXlsxOrderLoader/index.handler
      Runtime: nodejs12.x
      Description: ''
      MemorySize: 128
      Timeout: 15
      Policies:
      - AWSLambdaBasicExecutionRole
      - AmazonS3FullAccess
      - AmazonDynamoDBFullAccess
      Events:
        S3Event:
          Type: S3
          Properties:
            Bucket: !Ref olatexOrdersInputDirectory
            Events: S3:ObjectCreated:*

策略之后的行: 我添加了扩展 IAM 策略,因为我怀疑错误与权限不足有关,但它没有帮助。
下面我附加了从 SAM 的 template.yaml 生成的 CloudFormation 模板:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "An AWS Serverless Specification template describing your function.",
  "Resources": {
    "olatexXlsxOrderLoader": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Code": {
          "S3Bucket": "cloud9-026528720964-sam-deployments-eu-central-1",
          "S3Key": "6aa2a5885a77ea790684cb345d822ed8"
        },
        "Description": "",
        "Tags": [
          {
            "Value": "SAM",
            "Key": "lambda:createdBy"
          }
        ],
        "MemorySize": 128,
        "Handler": "olatexXlsxOrderLoader/index.handler",
        "Role": {
          "Fn::GetAtt": [
            "olatexXlsxOrderLoaderRole",
            "Arn"
          ]
        },
        "Timeout": 15,
        "Runtime": "nodejs12.x"
      }
    },
    "olatexXlsxOrderLoaderRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Action": [
                "sts:AssumeRole"
              ],
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com"
                ]
              }
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
          "arn:aws:iam::aws:policy/AmazonS3FullAccess",
          "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess"
        ],
        "Tags": [
          {
            "Value": "SAM",
            "Key": "lambda:createdBy"
          }
        ]
      }
    },
    "olatexOrdersInputDirectory": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "NotificationConfiguration": {
          "LambdaConfigurations": [
            {
              "Function": {
                "Fn::GetAtt": [
                  "olatexXlsxOrderLoader",
                  "Arn"
                ]
              },
              "Event": "S3:ObjectCreated:*"
            }
          ]
        }
      },
      "DependsOn": [
        "olatexXlsxOrderLoaderS3EventPermission"
      ]
    },
    "olatexXlsxOrderLoaderS3EventPermission": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "SourceAccount": {
          "Ref": "AWS::AccountId"
        },
        "FunctionName": {
          "Ref": "olatexXlsxOrderLoader"
        },
        "Principal": "s3.amazonaws.com"
      }
    }
  }
}

非常感谢您的帮助!
问候
安杰伊

最佳答案

基于评论。

该问题是由使用 S3:ObjectCreated:* 而不是 s3:ObjectCreated:* 引起的。

S3 事件名称区分大小写

关于amazon-web-services - AWS S3创建错误: "The event is not supported for notifications (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64634401/

相关文章:

amazon-web-services - 如何从 CloudFormation 启动 Glue 作业?

postgresql - FIPS 策略阻止访问 AWS 上的 RDS-Postgres

amazon-web-services - 使用 AWS IoT Core 规则和 AWS Lambda 处理嵌套 JSON 消息

amazon-web-services - 由于 VPC 问题,EC2 实例创建失败

amazon-web-services - Athena 在太多 S3 文件上的性能

amazon-web-services - 在 React-Native 中使用 AWS Amplify 显示来自 S3 的图像

amazon-web-services - 从在 cloudformation 自动缩放组中创建的实例获取实例 dns 名称

node.js - 如何使用 aws ses 在电子邮件 header 中添加姓名

ruby-on-rails - ActiveStorage 和 s3 - 默认设置所有公开的图像

amazon-web-services - 使用 CloudFormation 模板的可公开访问的 Elasticsearch 实例