serverless: Can't subscribe to S3 events on a bucket created with a stack
This is a Bug Report
Description
I know @flomotlik weighed in (#2154) on attaching events to s3 buckets not created by Cloudformation. I am having this issue with an s3 bucket that IS in the Cloudformation stack but it was created in the resources section of the serverless.yml:
functions:
upload-hook:
handler: api/upload-hook/index.handler
events:
- s3:
bucket: ${self:service}.${self:custom.stage}.assets
event: s3:ObjectCreated:*
resources:
Resources:
AssetsBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: "${self:service}.${self:custom.stage}.assets"
CorsConfiguration:
CorsRules:
- AllowedOrigins:
- http://example.dev:3001
AllowedHeaders:
- "*"
AllowedMethods:
- PUT
- GET
- AllowedOrigins:
- https://dev.example.com
AllowedHeaders:
- "*"
AllowedMethods:
- PUT
- GET
It seems that there are two sections in the cloudformation-template-update-stack.json one is named S3BucketExampleapidevassets and the other is named AssetsBucket. It seems that these should get merged by serverless.
Serverless Error ---------------------------------------
An error occurred while provisioning your stack: S3BucketExampleapidevassets
- example-api.dev.assets already exists in stack arn:aws:cloudformation:us-east-1:xxxxxx:stack/example-api-dev/de90bc30-aaa2-11e6-bd9e-500c20fafe62.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Your Environment Information -----------------------------
OS: darwin
Node Version: 7.0.0
Serverless Version: 1.1.0
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 4
- Comments: 18 (15 by maintainers)
Commits related to this issue
- Merge custom s3 bucket templates with the same bucket name. fixes #2717 — committed to asprouse/serverless by asprouse 8 years ago
- Merge custom s3 bucket templates with the same bucket name. fixes #2717 — committed to asprouse/serverless by asprouse 8 years ago
- Merge custom s3 bucket templates with the same bucket name. fixes #2717 — committed to asprouse/serverless by asprouse 8 years ago
@pmuens Thanks that looks promising, but still using a custom js config file that simulates naming.js seems like a lot of hoops to jump through to support something that seems like basic functionality.
Matching a generated resource id will be hard to explain to new users, especially when there are different conventions for each resource type that aren’t clear unless you read the code for naming.js.
I think that intelligent merging by bucket name (or at least explicitly mentioning the custom resource id in the http event) should be considered as an enhancement.
@pmuens I’m wondering what workaround works at this point. Trying to plug variables into resource ids does work. I get
Template format error: Resource name S3Bucket${self:custom.servicePrefix} is non alphanumeric.Can you shed some light on what can be done here?