Problem configuring bucket

I’m trying this out for the first time, and had an issue with deploying where my config creates a bucket, which triggers an event and runs a function. It says it already exists but no way in hades a bucket has this name. I tried different bucket names several times.

A bit of my config

custom:
bucket: uniquebucket-fhdjsjdhejcndjskdf

provider:
name: aws
runtime: nodejs8.10

iamRoleStatements:

  • Effect: Allow
    Action:

  • s3:*
    Resource: “*”

    postprocess:
    

    handler: api/handler.postprocess
    events:
    - s3:
    bucket: ${self:custom.bucket}
    event: s3:ObjectCreated:*
    rules:
    - suffix: .html

resources:
Resources:
S3UploadBucket:
Type: ‘AWS::S3::Bucket’
Properties:
BucketName: ${self:custom.bucket}

nasty little error

An error occurred: S3BucketUniquebucketfhdjsjdhejcndjskdf - uniquebucket-fhdjsjdhejcndjskdf already exists in stack arn:aws:cloudformation:us-east-1:278876728797:stack/html-pdf-dev/1f77d900-f92e-11e8-bd24
-0a16600979f0.

Any ideas what I am doing wrong?

@dixiehacker If you check the CloudFormation template generated by Serverless you’ll see you’re trying to create an S3 bucket under the resource S3UploadBucket with the name uniquebucket-fhdjsjdhejcndjskdfand Serverless is also trying to create an S3 bucket with that name under the resource S3BucketUniquebucketfhdjsjdhejcndjskdf

When you use bucket: ${self:custom.bucket} in the functions event Serverless automatically tries to create the S3 bucket for you with that name.

So which is it, set up the bucket using the function or set it up allocating it in the resources section? Adding “exist: true” doesn’t remove the error of pre-existing buckets.

Seems a tremendous catch-22. If I want lambda to act on a bucket item, sls creates the bucket first. If I want to setup resources to act on the bucket (set up an ses rule), it has to refer to the bucket.

Signed, Confused Noob

anyone ever figure this out? so confusing…