AWS event driver support for Dispatch
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
Dockerfile
Gopkg.lock
Gopkg.toml
LICENSE
README.md
cacert-2018-03-07.pem
driver.go
event-patterns-example.json

README.md

Dispatch Event Driver for AWS

This repo implements AWS event driver for Dispatch.

1. Get AWS credentials

Follow Get AWS Access Key to obtain aws region and credential, take a note for <aws_region>, <aws_access_key_id> and <aws_secret_access_key>. Create env varbiable for these two fields:

$ export AWS_AKID=<aws_access_key_id>
$ export AWS_SECRET_KEY=<aws_secret_access_key>

Then create a secret file:

$ cat << EOF > secret.json
{
    "aws_access_key_id": "${AWS_AKID}",
    "aws_secret_access_key": "${AWS_SECRET_KEY}"
}
EOF

Next, create a Dispatch secret which contains aws credentials:

$ dispatch create secret aws-credential secret.json
Created secret: aws-credential

2. Create Eventdrivertype in Dispatch

Create a Dispatch eventdrivertype with name aws:

$ dispatch create eventdrivertype aws dispatchframework/dispatch-events-aws:v0.0.1-solo
Created event driver type: aws

3. Create Eventdriver in Dispatch

When creating AWS eventdriver, following parameters should be specified properly:

  • region: obtained from step 1, default us-west-2
  • Two ways to invoke target: Event Pattern or Schedule:
    • event-patterns : setting up event patterns for AWS CloudWatch Rule, refer to AWS Event Pattern for more details. Example can be found in event-patterns-example.json.
    • schedule-expression : specifying event schedule expression, please refer to AWS Schedule Events for details.

Following parameters are optional (have defaults):

  • queue-name : specifying SQS queue name, default "dispatch"
  • duration : specifying SQS polling message duration, default "20" (0-20 seconds), which enables Long-polling
  • source : specifying event source, default "dispatch"
  • clean-up : clean up AWS resources after Driver shuts down. default false

All parameters should be configued through --set flag. For example, create a event driver using event-patterns:

$ dispatch create eventdriver aws --secret aws-credential --set region="us-west-2" --set event-patterns="[{\"source\":[\"aws.autoscaling\", \"aws.ec2\", \"aws.s3\"]}]" --set clean-up --name aws-events
Created event driver: aws-events

or using schedule-expression:

$ dispatch create eventdriver aws --secret aws-credential --set region="us-west-2" --set schedule-expression="rate(1 minute)" --set clean-up --name aws-events
Created event driver: aws-schedule-events

4. Create Subscription in Dispatch

To make events from eventdriver be processed by Dispatch, the last step is to create Dispatch subscription which sends events to a function. For example, to create a aws.autoscaling event subscription (bind to function hello-py):

$ dispatch create subscription hello-py --event-type="aws.s3" --name aws-sub-s3
created subscription: aws-sub-s3
$ dispatch create subscription hello-py --event-type="aws.s3" --name aws-sub-ec2
created subscription: aws-sub-ec2

event-type should be the AWS event source type that the subscription will be listening to. Please refer to AWS Event Types for more details.

NOTE: In subscription, event-type must match the CloudEvent attributes, otherwise Dispatch won't receive the event