Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
[add readme]
Browse files Browse the repository at this point in the history
  • Loading branch information
ste-xx committed Jul 5, 2018
1 parent dc86624 commit da48c1e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
73 changes: 73 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# S3 Metadata Eventhandler

Redirect S3 Events to Sns.
Use metadata as message attributes (see filtering with sns for more information)

## Env

```properties
TOPIC_ARN=Topic where message will be redirected
MANDATORY_META_DATA=S3 metadata which must exists otherwise an error will be raised and the message will not redirected. Comma seperated
```

## Example

```yaml

ExampleRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Policies:
- PolicyDocument:
Statement:
- Action:
- s3:GetObject
Effect: Allow
Resource:
- "*"
PolicyName: s3Policy
- PolicyDocument:
Statement:
- Action:
- sns:Publish
Effect: Allow
Resource:
- !Sub 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:*'
PolicyName: snsPolicy
- PolicyDocument:
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource:
- '*'
PolicyName: LogPolicy
Type: AWS::IAM::Role

ExampleTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: ' exampleTopic'

ExampleEventHandler:
Type: AWS::Lambda::Function
Properties:
Code:
...
Environment:
Variables:
MANDATORY_META_DATA: api-key-id, pid, transcribe-provider
TOPIC_ARN: !Ref 'ExampleTopic'
Handler: index.handler
Role: !GetAtt 'ExampleRole.Arn'
Runtime: nodejs8.10
```
10 changes: 1 addition & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@ exports.handler = async (event) => {
});
}, {});


//todo: mandatory fields
// if (!apiKeyId || !pid || !provider) {
// console.error("Mandatory fields not set");
// throw "Mandatory fields not set";
// }

console.log(`Send to ${TOPIC_ARN}`);
console.log(result);
console.log(`Send: ${JSON.stringify(result)} to ${TOPIC_ARN}`);

return snsApi.publish({
Message: 'placeholder',
Expand Down

0 comments on commit da48c1e

Please sign in to comment.