# Create an S3 event to an S3 bucket created with a resource definition

**URL:** https://forum.serverless.com/t/create-an-s3-event-to-an-s3-bucket-created-with-a-resource-definition/6993
**Category:** Serverless Framework
**Tags:** aws, lambda
**Created:** [January 14, 2019, 11:38am UTC](https://forum.serverless.com/t/create-an-s3-event-to-an-s3-bucket-created-with-a-resource-definition/6993 "2019-01-14T11:38:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![khinester](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/khinester/32/315_2.png) [@khinester](https://forum.serverless.com/u/khinester)
#### Post date: [January 14, 2019, 11:38am UTC](https://forum.serverless.com/t/create-an-s3-event-to-an-s3-bucket-created-with-a-resource-definition/6993/1 "2019-01-14T11:38:15Z")

</div>

Hello,  
I have the following serverless.yml file.

```
service: s3-playground

resources:
  Resources:
    EshotBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}
        LifecycleConfiguration:
          Rules:
            - Id: "Delayed csv expiration"
              Status: "Enabled"
              TagFilters:
                  - Key: "deleted-csv"
                    Value: "true"
              ExpirationInDays: 1
    EshotBucketLambdaPermission:
      Type: "AWS::Lambda::Permission"
      Properties:
        FunctionName:
          "Fn::GetAtt":
            - s3-playground-${opt:stage}-status
            - Arn
        Principal: "s3.amazonaws.com"
        Action: "lambda:InvokeFunction"
        SourceAccount:
          Ref: AWS::AccountId
        SourceArn: "arn:aws:s3:::${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}"
    EshotBucketPolicy:
      Type: AWS::S3::BucketPolicy
      Properties:
        Bucket: ${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}
        PolicyDocument:
          Statement:
            - Action:
                - s3:putObject
              Effect: "Allow"
              Principal:
                "AWS":
                  - "arn:aws:iam::#{AWS::AccountId}:root"
              Resource:
                - "arn:aws:s3:::${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}/*.xls"
                - "arn:aws:s3:::${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}/*.csv"
                - "arn:aws:s3:::${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}/*.tsv"
                - "arn:aws:s3:::${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}/*.xlsx"

package:
 exclude:
   - ./**
 include:
   - ./status

provider:
  name: aws
  runtime: go1.x
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:getObject
        - s3:putObject
        - s3:putBucketPolicy
        - states:startExecution
      Resource: "*"
  stage: ${opt:stage}
  region: ${file(./config.yml):${opt:stage}.REGION}
  environment:
    UPLOADS_BUCKET: ${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}
functions:
  status:
    handler: status
    memorySize: 128
    events:
      - s3:
          bucket: ${file(./config.yml):${opt:stage}.UPLOADS_BUCKET}
          event: s3:ObjectCreated:*
    timeout: 60
    environment:
      REGION: ${file(./config.yml):${opt:stage}.REGION}

```

what is the correct way to attach the `status` to the resource bucket?

I get this error:

```
Serverless: Validating template...

  Error --------------------------------------------------

  The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource s3-playground-prod-status

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs: docs.serverless.com
     Bugs: github.com/serverless/serverless/issues
     Issues: forum.serverless.com

  Your Environment Information -----------------------------
     OS: linux
     Node Version: 9.11.1
     Serverless Version: 1.30.0

Makefile:18: recipe for target 'deploy' failed
make: *** [deploy] Error 1

```

[https://github.com/serverless/serverless/issues/3034](https://github.com/serverless/serverless/issues/3034) - looks that the issue is still open

---

<div class="post-metadata">

### Author: ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)
#### Post date: [January 15, 2019, 10:30am UTC](https://forum.serverless.com/t/create-an-s3-event-to-an-s3-bucket-created-with-a-resource-definition/6993/2 "2019-01-15T10:30:25Z")

</div>

Your `Fn::GetAtt` should probably be:

```auto
Fn::GetAtt:
  - StatusLambdaFunction
  - Arn

```
