SlideShare a Scribd company logo
Page 1 of 12
Push Lambda Logs/Events Into Splunk Cloud
Revision Number Date Author Comments
1 7/13/2018 First Draft By
Varun Kumar
Document Purpose: -
 Capture all the steps needed to ingest log from Lambda function into SplunkCloud in real time.
 Standardise the apprach to capture the logs across lambda functions.
Usecase :-
 A lambda function will be created that will be used to start/stop ecs instances.
 Everytime the lambda is invoke the logs will be routed to SplunkCloud using SplunkHEC(http event
collector)
The architecture followed is
Page 2 of 12
Table of Content
1 Splunk Setup............................................................................................................. 3
Splunk Index...................................................................................................................... 3
Enable HEC........................................................................................................................ 3
HEC Token Creation ......................................................................................................... 4
Modify SourceType ........................................................................................................... 5
2 Testing From StandAlone Client............................................................................. 6
3 Creating Lambda Function ...................................................................................... 7
Creating Sandalone Splunk Lambda Function .............................................................. 7
Application Lambda Function........................................................................................ 10
Invoking Splunk Lambda Function From Application Lambda.................................. 11
Trigger Splunk Lambda From App Lambda ................................................................. 12
Page 3 of 12
1 Splunk Setup
Splunk Index
Create a new index
Enable HEC
Setup the HEC collector
Page 4 of 12
HEC Token Creation
IndexerAcknowledgement will be needed only in case of critical messages that should not be missed at
any cost.
Page 5 of 12
Modify SourceType
Modiy the source type and add it to the HEC token
Page 6 of 12
2 Testing From StandAlone Client
Checking for logs in spunk
Page 7 of 12
3 Creating Lambda Function
Creating Sandalone Splunk Lambda Function
We will now create a lambda function that will act as a standalone splunk logging lambda function and will
be anonymous of the application code. This lambda can be called from all other application lambda
functions and the events wll be populated to SplunkCloud.
Enter the token and URL
Page 8 of 12
Modify the Splunk blueprint code with the code given below. Modified.
Page 9 of 12
/**
* Splunk logging for AWS Lambda
*
* This function logs to a Splunk host using Splunk's HTTP event collector API.
*
* Define the following Environment Variables in the console below to configure
* this function to log to your Splunk host:
*
* 1. SPLUNK_HEC_URL: URL address for your Splunk HTTP event collector endpoint.
* Default port for event collector is 8088. Example: https://host.com:8088/services/collector
*
* 2. SPLUNK_HEC_TOKEN: Token for your Splunk HTTP event collector.
* To create a new token for this Lambda function, refer to Splunk Docs:
* http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector#Create_an_Event_Collector_token
*/
'use strict';
const loggerConfig = {
url: process.env.SPLUNK_HEC_URL,
token: process.env.SPLUNK_HEC_TOKEN,
};
const SplunkLogger = require('./lib/mysplunklogger');
const logger = new SplunkLogger(loggerConfig);
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2));
// Log JSON objects to Splunk
logger.log(event);
// Log JSON objects with optional 'context' argument (recommended)
// This adds valuable Lambda metadata including functionName as source, awsRequestId as field
Page 10 of 12
logger.log(event, context);
// Log strings
logger.log(`value1 = ${event}`, context);
//logger.log(`value1 = ${event.key1}`, context);
// Log with user-specified timestamp - useful for forwarding events with embedded
// timestamps, such as from AWS IoT, AWS Kinesis, AWS CloudWatch Logs
// Change "Date.now()" below to event timestamp if specified in event payload
logger.logWithTime(Date.now(), event, context);
// Advanced:
// Log event with user-specified request parameters - useful to set input settings per event vs token-level
// Full list of request parameters available here:
// http://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTinput#services.2Fcollector
logger.logEvent({
time: Date.now(),
host: 'serverless',
source: `lambda:${context.functionName}`,
sourcetype: 'httpevent',
event: event,
});
// Send all the events in a single batch to Splunk
logger.flushAsync((error, response) => {
if (error) {
callback(error);
} else {
console.log(`Response from Splunk:n${response}`);
//callback(null, event.key1); // Echo back the first key value
callback(null, event); // Echo back the first key value
}
});
};
Application Lambda Function
The application lambda function willstart ec2 instances based on the parameters passed to the lambda.
Test the lambda and ensure the working standalone.
Page 11 of 12
Invoking Splunk Lambda Function From Application Lambda
modify the application Lambda function to be able to invoke the Splunk Lambda function.
modify the roles assigned to the App Lambda as shown in the screenshot below.
Page 12 of 12
Trigger Splunk Lambda From App Lambda
Checking the cloud watch logs for Application Lambda and you will see it has invoked the Splunk Lambda.
check for logs in splunk with the instance id in the event.

More Related Content

PPTX
Building Microservices with Spring Cloud and Netflix OSS
PDF
Stabilizing the Jenga tower: Scaling out Ceilometer
PDF
Ceilometer presentation ods havana final - published
PDF
Kubernetes and Prometheus
PDF
Microservices with Netflix OSS and Spring Cloud
PDF
Apache Flink and More @ MesosCon Asia 2017
PDF
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
PPTX
Spring Cloud and Netflix Components
Building Microservices with Spring Cloud and Netflix OSS
Stabilizing the Jenga tower: Scaling out Ceilometer
Ceilometer presentation ods havana final - published
Kubernetes and Prometheus
Microservices with Netflix OSS and Spring Cloud
Apache Flink and More @ MesosCon Asia 2017
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
Spring Cloud and Netflix Components

What's hot (20)

PDF
Spring cloud Service-Discovery
PPT
Scalable Event Tracking
PDF
What Does Kubernetes Look Like?: Performance Monitoring & Visualization with ...
PDF
Apache Flink® Meets Apache Mesos® and DC/OS
PDF
How we use Fluentd in Treasure Data
PDF
Apache Flink Meets Apache Mesos And DC/OS @ Mesos Meetup Berlin
PDF
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
PPTX
Riga dev day: Lambda architecture at AWS
PPTX
Flink Forward SF 2017: Stephan Ewen - Convergence of real-time analytics and ...
PDF
Flink forward SF 2017: Ufuk Celebi - The Stream Processor as a Database: Buil...
PDF
Scala usergroup stockholm - reactive integrations with akka streams
PPTX
DC Spark bake off - Realtime TCP Packet Analysis using Spark and Azure Event ...
PDF
DevOps Days Tel Aviv - Serverless Architecture
PPTX
Flink Forward SF 2017: Timo Walther - Table & SQL API – unified APIs for bat...
PDF
Akka streams - Umeå java usergroup
PPTX
Spark with kubernates
PPTX
LowlaDB intro March 2015
PDF
Spring Cloud and Netflix OSS overview v1
PDF
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
PDF
Spark Your Legacy (Spark Summit 2016)
Spring cloud Service-Discovery
Scalable Event Tracking
What Does Kubernetes Look Like?: Performance Monitoring & Visualization with ...
Apache Flink® Meets Apache Mesos® and DC/OS
How we use Fluentd in Treasure Data
Apache Flink Meets Apache Mesos And DC/OS @ Mesos Meetup Berlin
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Riga dev day: Lambda architecture at AWS
Flink Forward SF 2017: Stephan Ewen - Convergence of real-time analytics and ...
Flink forward SF 2017: Ufuk Celebi - The Stream Processor as a Database: Buil...
Scala usergroup stockholm - reactive integrations with akka streams
DC Spark bake off - Realtime TCP Packet Analysis using Spark and Azure Event ...
DevOps Days Tel Aviv - Serverless Architecture
Flink Forward SF 2017: Timo Walther - Table & SQL API – unified APIs for bat...
Akka streams - Umeå java usergroup
Spark with kubernates
LowlaDB intro March 2015
Spring Cloud and Netflix OSS overview v1
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
Spark Your Legacy (Spark Summit 2016)
Ad

Similar to Publishing AwsLlambda Logs Into SplunkCloud (20)

PDF
SplunkSummit 2015 - HTTP Event Collector, Simplified Developer Logging
PDF
Anz summit 2015 http event collector - sydney
PPTX
Liberate your Application Logging
PPTX
HTTP Event Collector, Simplified Developer Logging
PPTX
Getting Data into Splunk
PDF
Deep Visibility: Logging From Distributed Microservices
PPTX
Splunk Architecture
ODP
Splunk
PPTX
Splunk HTTP Event Collector
PPTX
Splunk Discovery: Warsaw 2018 - Getting Data In
PDF
Choose Your Own Adventure to Get Started with Grafana Loki
PPTX
SplunkLive! Developer Breakout
PPTX
Workshop splunk 6.5-saint-louis-mo
PDF
Machine Data 101
PPTX
Machine Data 101: Turning Data Into Insight
PDF
Encontro anual para apresentação das novidades da .conf23
PDF
Splunk workshop-Machine Data 101
PPTX
Securing the Enterprise/Cloud with Splunk at the Centre
PPTX
Clear the Mist from your Clouds with Splunk
PPTX
Take an Analytics-driven Approach to Container Performance with Splunk for Co...
SplunkSummit 2015 - HTTP Event Collector, Simplified Developer Logging
Anz summit 2015 http event collector - sydney
Liberate your Application Logging
HTTP Event Collector, Simplified Developer Logging
Getting Data into Splunk
Deep Visibility: Logging From Distributed Microservices
Splunk Architecture
Splunk
Splunk HTTP Event Collector
Splunk Discovery: Warsaw 2018 - Getting Data In
Choose Your Own Adventure to Get Started with Grafana Loki
SplunkLive! Developer Breakout
Workshop splunk 6.5-saint-louis-mo
Machine Data 101
Machine Data 101: Turning Data Into Insight
Encontro anual para apresentação das novidades da .conf23
Splunk workshop-Machine Data 101
Securing the Enterprise/Cloud with Splunk at the Centre
Clear the Mist from your Clouds with Splunk
Take an Analytics-driven Approach to Container Performance with Splunk for Co...
Ad

More from varun kumar karuna (7)

PDF
Regular expressions
DOCX
removeNameSpacePrefix
PDF
BW6AutomationUsingBamboo
PDF
TibcoBW6.0
DOCX
InvokingRestThroughHttpPalette
DOC
TableauDevelopment
PDF
TibcoBE-Development
Regular expressions
removeNameSpacePrefix
BW6AutomationUsingBamboo
TibcoBW6.0
InvokingRestThroughHttpPalette
TableauDevelopment
TibcoBE-Development

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
August Patch Tuesday
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Hybrid model detection and classification of lung cancer
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
A Presentation on Touch Screen Technology
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
project resource management chapter-09.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Univ-Connecticut-ChatGPT-Presentaion.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
August Patch Tuesday
Chapter 5: Probability Theory and Statistics
Enhancing emotion recognition model for a student engagement use case through...
Hybrid model detection and classification of lung cancer
Encapsulation_ Review paper, used for researhc scholars
Group 1 Presentation -Planning and Decision Making .pptx
A Presentation on Touch Screen Technology
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
project resource management chapter-09.pdf
WOOl fibre morphology and structure.pdf for textiles
Assigned Numbers - 2025 - Bluetooth® Document
TLE Review Electricity (Electricity).pptx
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
A comparative analysis of optical character recognition models for extracting...
Zenith AI: Advanced Artificial Intelligence
NewMind AI Weekly Chronicles - August'25-Week II

Publishing AwsLlambda Logs Into SplunkCloud

  • 1. Page 1 of 12 Push Lambda Logs/Events Into Splunk Cloud Revision Number Date Author Comments 1 7/13/2018 First Draft By Varun Kumar Document Purpose: -  Capture all the steps needed to ingest log from Lambda function into SplunkCloud in real time.  Standardise the apprach to capture the logs across lambda functions. Usecase :-  A lambda function will be created that will be used to start/stop ecs instances.  Everytime the lambda is invoke the logs will be routed to SplunkCloud using SplunkHEC(http event collector) The architecture followed is
  • 2. Page 2 of 12 Table of Content 1 Splunk Setup............................................................................................................. 3 Splunk Index...................................................................................................................... 3 Enable HEC........................................................................................................................ 3 HEC Token Creation ......................................................................................................... 4 Modify SourceType ........................................................................................................... 5 2 Testing From StandAlone Client............................................................................. 6 3 Creating Lambda Function ...................................................................................... 7 Creating Sandalone Splunk Lambda Function .............................................................. 7 Application Lambda Function........................................................................................ 10 Invoking Splunk Lambda Function From Application Lambda.................................. 11 Trigger Splunk Lambda From App Lambda ................................................................. 12
  • 3. Page 3 of 12 1 Splunk Setup Splunk Index Create a new index Enable HEC Setup the HEC collector
  • 4. Page 4 of 12 HEC Token Creation IndexerAcknowledgement will be needed only in case of critical messages that should not be missed at any cost.
  • 5. Page 5 of 12 Modify SourceType Modiy the source type and add it to the HEC token
  • 6. Page 6 of 12 2 Testing From StandAlone Client Checking for logs in spunk
  • 7. Page 7 of 12 3 Creating Lambda Function Creating Sandalone Splunk Lambda Function We will now create a lambda function that will act as a standalone splunk logging lambda function and will be anonymous of the application code. This lambda can be called from all other application lambda functions and the events wll be populated to SplunkCloud. Enter the token and URL
  • 8. Page 8 of 12 Modify the Splunk blueprint code with the code given below. Modified.
  • 9. Page 9 of 12 /** * Splunk logging for AWS Lambda * * This function logs to a Splunk host using Splunk's HTTP event collector API. * * Define the following Environment Variables in the console below to configure * this function to log to your Splunk host: * * 1. SPLUNK_HEC_URL: URL address for your Splunk HTTP event collector endpoint. * Default port for event collector is 8088. Example: https://host.com:8088/services/collector * * 2. SPLUNK_HEC_TOKEN: Token for your Splunk HTTP event collector. * To create a new token for this Lambda function, refer to Splunk Docs: * http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector#Create_an_Event_Collector_token */ 'use strict'; const loggerConfig = { url: process.env.SPLUNK_HEC_URL, token: process.env.SPLUNK_HEC_TOKEN, }; const SplunkLogger = require('./lib/mysplunklogger'); const logger = new SplunkLogger(loggerConfig); exports.handler = (event, context, callback) => { console.log('Received event:', JSON.stringify(event, null, 2)); // Log JSON objects to Splunk logger.log(event); // Log JSON objects with optional 'context' argument (recommended) // This adds valuable Lambda metadata including functionName as source, awsRequestId as field
  • 10. Page 10 of 12 logger.log(event, context); // Log strings logger.log(`value1 = ${event}`, context); //logger.log(`value1 = ${event.key1}`, context); // Log with user-specified timestamp - useful for forwarding events with embedded // timestamps, such as from AWS IoT, AWS Kinesis, AWS CloudWatch Logs // Change "Date.now()" below to event timestamp if specified in event payload logger.logWithTime(Date.now(), event, context); // Advanced: // Log event with user-specified request parameters - useful to set input settings per event vs token-level // Full list of request parameters available here: // http://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTinput#services.2Fcollector logger.logEvent({ time: Date.now(), host: 'serverless', source: `lambda:${context.functionName}`, sourcetype: 'httpevent', event: event, }); // Send all the events in a single batch to Splunk logger.flushAsync((error, response) => { if (error) { callback(error); } else { console.log(`Response from Splunk:n${response}`); //callback(null, event.key1); // Echo back the first key value callback(null, event); // Echo back the first key value } }); }; Application Lambda Function The application lambda function willstart ec2 instances based on the parameters passed to the lambda. Test the lambda and ensure the working standalone.
  • 11. Page 11 of 12 Invoking Splunk Lambda Function From Application Lambda modify the application Lambda function to be able to invoke the Splunk Lambda function. modify the roles assigned to the App Lambda as shown in the screenshot below.
  • 12. Page 12 of 12 Trigger Splunk Lambda From App Lambda Checking the cloud watch logs for Application Lambda and you will see it has invoked the Splunk Lambda. check for logs in splunk with the instance id in the event.