awsdocs/aws-sam-developer-guide

generate event for sns about new put event in S3 -- bug/example

dancaspi opened this issue · 2 comments

Hey all,
SAM is great, but I am missing documentation on how to generate local events for debugging and local runs. for S3 it works as shown on the site. however if I am looking for an SNS based events (which alerts on an S3 event) I am a bit at a lost:

sam local generate-event sns notification --message "($cat s3_put_event.json)"

the above was suggested as solution but it intorduces quotes in the message part:
the message portion of the notification looks something like this:

"Message": "{
  "Records": [
    {...}]... }"

the problematic part is the encapsulating quotes around the message that shouldn't be there.,

any help would be appreciated,
Dan

So.. at least for me, the issue was solved by using a bit of sed, but i think it should be fixed somehow (or i am missing something). the problem turns out to be twofold: the message is in fact a string, so that's ok. but it needs to be completely escaped to be json: once for quotation marks and once for newlines. the eventual solution that worked for me was:

sam local generate-event sns notification --message "$(sam local generate-event s3 put --bucket yourbucket --key your/file/key.txt | sed 's/\"/\\"/g' | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')" > s3_put_event_via_sns_notification.json

and so you will have a json that properly serves as input for local run of SAM and parses correctly. Am I missing something? I am running version SAM CLI 0.47.0

should this be closed?

Closing this issue or pull request in advance of archiving this repo. For more information about the decision to archive this repo (and others in the "awsdocs" org), see the announcement on the AWS News Blog.