Serverless computing has taken off in recent years with more efficient cloud services. AWS Lambda is a great example of this, where provisioning and management of resources happens from the service’s end. You only have to deal with the code. This article will give a brief overview of AWS Lambda in contrast to EC2 instances, then walk through shipping AWS Lambda metrics to Logz.io.

The idea with this kind of service is to provide a lean option for developers who are without the need of a robust virtual infrastructure.

AWS Lambda is Amazon’s event-based computing service for running code without having to manage servers. Users apply Lambda to things APIs, S3 buckets, and DynamoDB tables. Consequently, it produces telemetry the same as EC2 instances, producing logs and metrics via CloudWatch.

Code in Lambda is called a function. Lambda functions can be in Python, node.js, Ruby, Java, GoLang and .NET (and several versions of each as well). This means that Lambda’s main limitation is to apps that use the aforementioned languages.

 

AWS EC2 vs. Lambda

On availability, Lambda is far more convenient. Lambda is meant to be efficient, being a tradeoff relative to EC2 instances in that you can’t log into individual instances. EC2s require management and provisioning. AWS charges according to compute time and won’t charge its customers when the code isn’t running. The AWS Lambda service offers virtual machines, load balancing, and scaling without customers having to get their hands dirty.

It wouldn’t be fair to say EC2 operates on-demand while Lambda doesn’t. EC2 instances are always running, while events switch Lambda on and off. In addition, there are a number of use cases that contrast the two tools.

EC2 instances are mainly for hosting, high performance computing, and disaster recovery. However, Lambda can automate tasks and deal with a few real-time tasks (log analysis, filtering, and transforming data). Actions from a few sources trigger Lambda—S3 buckets, API Gateway, Alexa devices or AWS IOT, DynamoDB, and SNS.

While EC2 has snapshotting available, it’s more complex than Lambda’s. Lambda keeps records of versions of its functions and even lets you organize them by category.

Ship AWS Lambda Metrics to Logz.io

Logz.io uses its Docker Metrics Collector, a container running metricbeat alongside your modules at runtime.

Set Up an IAM User

Retrieve your IAM user or make a new one. Create (if you haven’t already) an Access Key ID and Secret Access Key. Subsequrntly, make sure the IAM user you have or you are creating has the following seven permissions:

cloudwatch:GetMetricData
cloudwatch:ListMetrics
ec2:DescribeInstances
ec2:DescribeRegions
iam:ListAccountAliases
sts:GetCallerIdentity
tag:GetResources

Select Your Metrics Region

Amazon has many regions available, each centering in specific countries or cities. Some have more than one option. US East has two choices in either northern Virginia or Ohio; Asia Pacific northeast out of Tokyo; etc.

Each will have its own slug, like us-east-1, us-east-2, ap-northeast-1, etc. Find and copy the relevant slug to your text editor.
Next, pull the Docker image docker-collector-metrics:

docker pull logzio/docker-collector-metrics

Run the Container

You’ll set your configuration using environment variables in the docker run command. Format each parameter like this: --env ENV_VARIABLE_NAME="value".

See the optional parameters below the code block. All the parameters in the code are required.

docker run --name docker-collector-metrics \
--env LOGZIO_TOKEN="<>" \
--env LOGZIO_MODULES="aws" \
--env AWS_ACCESS_KEY="<>" \
--env AWS_SECRET_KEY="<>" \
--env AWS_REGION="<>" \
--env AWS_NAMESPACES="<>" \
logzio/docker-collector-metrics

LOGZIO_REGION, LOGZIO_TYPE, LOGZIO_LOG_LEVEL, LOGZIO_EXTRA_DIMENSIONS, and DEBUG are optional settings. If you wish to add any of them, here they are in their proper formats:

--env LOGZIO_REGION="uk" \
--env LOGZIO_TYPE="docker-collector-metrics" \
--env LOGZIO_LOG_LEVEL="INFO" \
--env LOGZIO_EXTRA_DIMENSIONS="dimensionName1=value1" \
--env DEBUG=”false” \

Open Your Lambda Dashboard in Logz.io
Your metrics should appear after a few minutes in the dashboard in your Logz.io Metrics account. To open it, go to Manage in the left menu, then click Logz.io Dashboards > Cloudwatch AWS/Lambda.