AWS S3 creation error: "The event is not supported for notifications (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument"
Asked Answered
F

1

5

I'm developing my first lambda in Code9 that suppose to be triggered by S3 event. Unfortunetly, when I'm trying to deploy, I'm constantly getting CloudFormation Error:

"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)"


See below CloudFormation events from AWS Mgm Console:

enter image description here

Below is my AWS SAM template.yaml file:

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:*

Lines after Policies: I've added to extend IAM policies because I was suspecting error is related to insufficient privilages but it doesn't helped.
Below I'm attaching CloudFormation templte that is generated from SAM's template.yaml:

{
  "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"
      }
    }
  }
}

Thanks a lot for all your help!
Regards
Andrzej

Fernferna answered 1/11, 2020 at 16:50 Comment(3)
Can you try with s3:ObjectCreated:*, rather then with S3:ObjectCreated:*. Maybe events name are case-sensitive?Ballottement
It worked! Thanks man- I would look for that for years!Fernferna
Glad to hear that. If you don't mind I will provide an answer for future rerefence.Ballottement
B
18

Based on the comments.

The issue was caused by using S3:ObjectCreated:*, rather then s3:ObjectCreated:*.

S3 event names are case-sensitive.

Ballottement answered 2/11, 2020 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.