Invocations via AWS EventBridge and AWS SNS are untested and should be considered experimental. If the content of the events is not relevant to the handler function, consider passing function(x) list() to the deserialiser argument of lambda_config to ignore the event content.

Otherwise, it’s highly recommended to allow the handler function to accept ... arguments, so that superfluous arguments can be ignored.

EventBridge events

The lambdr package, by default, will extract the “detail” from invocations via EventBridge. If the invocation is via a scheduled event the detail will likely be empty, and so no arguments will be passed to the handler function.

An example EventBridge event content (as a JSON) containing the “detail” is below:

For more information on Event Bridge events, refer to the official documentation.

SNS Events

The lambdr package, by default, will extract the “message” from the “record” of invocations via SNS. If the message is a valid JSON it will be parsed into a list. Otherwise it will be passed to the handler function as a single string.

An example SNS event body (as a JSON), of which the message is a part, is below. This example is the result of a CloudWatch alarm being triggered and passed to SNS:

      "Records": [
              "EventSource": "aws:sns",
              "EventVersion": "1.0",
              "EventSubscriptionArn": "arn:aws:sns:ap-southeast-2:1234567890:lambda-parity-test:123456abcdef",
              "Sns": {
                  "Type": "Notification",
                  "MessageId": "123456abcdef",
                  "TopicArn": "arn:aws:sns:ap-southeast-2:1234567890:lambda-parity-test",
                  "Subject": "INSUFFICIENT_DATA: \\"test-lambda-parity\\" in Asia Pacific (Sydney)",
                  "Message": "{\\"AlarmName\\":\\"test-lambda-parity\\",\\"AlarmDescription\\":null,\\"AWSAccountId\\":\\"1234567890\\",\\"NewStateValue\\":\\"INSUFFICIENT_DATA\\",\\"NewStateReason\\":\\"Insufficient Data: 1 datapoint was unknown.\\",\\"StateChangeTime\\":\\"2021-10-21T10:20:50.932+0000\\",\\"Region\\":\\"Asia Pacific (Sydney)\\",\\"AlarmArn\\":\\"arn:aws:cloudwatch:ap-southeast-2:1234567890:alarm:test-lambda-parity\\",\\"OldStateValue\\":\\"ALARM\\",\\"Trigger\\":{\\"MetricName\\":\\"NumberOfObjects\\",\\"Namespace\\":\\"AWS/S3\\",\\"StatisticType\\":\\"Statistic\\",\\"Statistic\\":\\"MAXIMUM\\",\\"Unit\\":null,\\"Dimensions\\":[{\\"value\\":\\"random-data\\",\\"name\\":\\"BucketName\\"},{\\"value\\":\\"AllStorageTypes\\",\\"name\\":\\"StorageType\\"}],\\"Period\\":60,\\"EvaluationPeriods\\":1,\\"ComparisonOperator\\":\\"GreaterThanOrEqualToThreshold\\",\\"Threshold\\":0.0,\\"TreatMissingData\\":\\"- TreatMissingData:                    missing\\",\\"EvaluateLowSampleCountPercentile\\":\\"\\"}}",
                  "Timestamp": "2021-10-21T10:20:50.973Z",
                  "SignatureVersion": "1",
                  "Signature": "abcdefghijklmnopqrstubwxyz",
                  "SigningCertUrl": "",
                  "UnsubscribeUrl": "",
                  "MessageAttributes": {}

Note that the message is stringified within the JSON. Its JSON representation is: