AWS Lambda function for sending AWS SNS messages to Logentries in near real-time for processing and analysing
When a message is published to an SNS topic that has a Lambda function subscribed to it, the Lambda function is invoked with the payload of the published message. That message gets forwarded to Logentries by this script, using token TCP.
- Log in to your Logentries account
- Add a new token based log
- Optional: repeat to add second log for debugging
-
Create a new Lambda function
-
On the "Select Blueprint" screen, press "Skip"
-
Configure function:
- Give your function a name
- Set runtime to Python 2.7
-
Edit code:
- Edit the contents of
le_config.py
- Replace values of
log_token
anddebug_token
with tokens obtained earlier. - Create a .ZIP file, containing the updated
le_config.py
,le_sns.py
and the foldercertifi
- Make sure the files and
certifi
folder are in the root of the ZIP archive
- Make sure the files and
- Choose "Upload a .ZIP file" in "Code entry type" dropdown and upload the archive created in previous step
- Edit the contents of
-
Lambda function handler and role
- Change the "Handler" value to
le_sns.lambda_handler
- Create a new basic execution role (your IAM user must have sufficient permissions to create & assign new roles)
- Change the "Handler" value to
-
Allocate resources:
- Set memory to 128 MB
- Set timeout to ~1 minute (script only runs for seconds at a time)
-
Enable function:
- Click "Create function"
-
Sign in to the AWS Management Console and open the Amazon SNS console at https://console.aws.amazon.com/sns/.
-
In the left Navigation pane, click Topics, and then click the topic to which you want to subscribe a Lambda endpoint.
-
Click Actions and then click Subscribe to topic.
-
In the Protocol drop-down box, select AWS Lambda.
-
In the Endpoint drop-down box, select the ARN for the Lambda function.
-
In the Version or Alias drop-down box, select an available version or alias to use. You can also choose $LATEST to specify the latest version of the Lambda function. If you do not want to specify a version or alias, you can also choose default, which is functionally the same as $LATEST.
-
Click Create subscription.
-
Watch your logs come in:
- Navigate to your Logentries account and watch your SNS messages appear.