New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deploying S3 bucket with SNS notification event not possible #4797
Comments
This template works. It's a bit messier than I'd like. IMO Serverless should handle this automatically. service:
name: TestStack
# Add the serverless-webpack plugin
plugins:
- serverless-webpack
provider:
name: aws
runtime: nodejs6.10
variableSyntax: '\$\(([\s\S]+?)\)'
custom:
stage: $(opt:stage, self:provider.stage)
topicName: kerpow
topic: $(self:service)-$(self:custom.topicName)-$(self:custom.stage)
topicArn:
Fn::Sub: arn:aws:sns:$(self:provider.region):${AWS::AccountId}:$(self:custom.topic)
functions:
first:
handler: first.hello
events:
- sns: $(self:custom.topic)
resources:
Resources:
TestBucket:
Type: AWS::S3::Bucket
DependsOn: SNSTopicPolicy
Properties:
BucketName: aa-test-95872017
NotificationConfiguration:
TopicConfigurations:
- Event: s3:ObjectCreated:Put
Filter:
S3Key:
Rules:
- Name: prefix
Value: staging/
Topic: $(self:custom.topicArn)
SNSTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
AWS: "*"
Action: sns:Publish
Resource: $(self:custom.topicArn)
Condition:
ArnLike:
aws:SourceArn: arn:aws:s3:::aa-test-95872017
Topics:
- Ref: SNSTopic$(self:service)$(self:custom.topicName)$(self:custom.stage) |
@HyperBrain @dschep Just following up on an old issue that's probably still existent. |
Hi, How to solve that ? |
@hdryx you will get this error if any of your variables contain "-" characters. Serverless generates the final topic name out of the original name while removing "-". So if your topic is called "normalize-lambda-dev-raw-ingest" then the Ref would be "SNSTopicNormalizelambda${self:custom.stage}rawingest". Hope that helps |
What is the state of this? Is the solution provided by @ffxsam still the best option? |
This is a Bug Report
Description
For bug reports:
It's not possible to deploy a stack with an S3 bucket that has an SNS topic as an event notification. Is something missing in the CloudFormation file generated by Serverless? According to this AWS support article, it seems an
AWS::SNS::TopicPolicy
is needed, and this is not generated by Serverless:https://aws.amazon.com/premiumsupport/knowledge-center/unable-validate-destination-s3/
The stack should deploy without errors.
See bottom for
serverless.yml
file.Additional Data
serverless.yaml:
The text was updated successfully, but these errors were encountered: