Skip to content
Clojure Library to create Cloudwatch Events and Rules for Lambdas
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.
.circleci first commit - orb abstraction May 12, 2019
src/orb
test/orb
.gitignore first commit - orb abstraction May 12, 2019
LICENSE.txt Add LICENSE May 12, 2019
README.org do not shadow clojure.core fns May 13, 2019
deps.edn first commit - orb abstraction May 12, 2019

README.org

About

Clojure Library to create Cloudwatch Events and Rules for Lambdas

orb is an abstraction over Cloudwatch Events that encapsulates given Lambda Target, the Trigger(Schedule or Resource event) and the Input to the Target when the Trigger occurs.

(require '[orb.core :as orb])
(orb/init! {:auth-type :profile
            :profile :qa})

orb supports following event types:

  1. Scheduled Events - cron-type events
  2. Resource Events - Arbitrary events generated by AWS services
  3. Adhoc Events - Arbitrary invocation of a Lambda, both synchronously and asychronously

Scheduled Events

Orb rules can be Schedule Events - cron or rate. https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

Below orb sets up a schedule to trigger the given Lambda every 5 mins. `:input` value is an edn-map that is sent as an event to the Lambda

(orb/create! "test-rule-1"
             :lambda   "arn:aws:lambda:us-east-1:ACC:function:my-lambda-name"
             :rule     "rate(5 minutes)"
             :input    {:message "hello world"})

Below orb sets up a schedule to trigger the given Lambda every midnight UTC.

(orb/create! "test-rule-2"
             :lambda   "arn:aws:lambda:us-east-1:ACC:function:my-lambda-name"
             :rule     "cron(0 0 * * ? *)"
             :input    {:cue :health.ping :param {}})

Resource Events

`orb` provides a list of pre-defined Event Patterns. Example :s3-bucket-change

(orb/create! "test-rule-3"
             :lambda   "arn:aws:lambda:us-east-1:ACC:function:my-lambda-name"
             :rule    {:id :s3-bucket-change :bucket "my-s3-bucket"}
             :input   {:cue :upload-data :param {:path "s3-path"}}

To list orbs

(orb/list-rules)
=> ({:name "test-rule-1",
     :state "ENABLED",
     :rule  "rate(5 minutes)"}
    {:name "test-rule-2",
     :state "ENABLED",
     :rule  "cron(0 0 * * ? *)"}
    ...)

To delete the rule

(orb/delete! "test-rule-1")

Adhoc Events

request invokes the Lambda and returns the response value with the associated log.

(orb/request lambda-name payload)
(orb/request "my-lambda-name" {:cue "health.ping" :param {}})

=> {:response "pong",
    :log
    ["START RequestId: 9d1578f3-d4b6-489e-958e-84e7c7cc30b2 Version: $LATEST"
     ":input {:cue health.ping, :param {}}"
     "END RequestId: 9d1578f3-d4b6-489e-958e-84e7c7cc30b2"
     "REPORT RequestId: 9d1578f3-d4b6-489e-958e-84e7c7cc30b2\tDuration: 63.79 ms\tBilled Duration: 100 ms \tMemory Size: 1024 MB\tMax Memory Used: 199 MB\t"],
    :error nil,
    :version "$LATEST"}

send is async and returns immediately with a trackable ID

(orb/send! "partman-lambda" {:cue :eventlog.add-partitions :param {}})

License - Apache 2.0

Copyright 2019 Omnyway Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.