Problem configuring bucket


#1

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?


#2

@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.