Description:
AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume - there is no charge when your code is not running.
Rationale:
AWS CloudTrail records API calls used within an AWS account, including calls made from the AWS Management Console, SDKs, command-line tools, and other AWS services. If you turn on data event logging, CloudTrail will also log function invocations, so you can see which identities are invoking the functions and the frequency of their invocations.
Impact:
One of the benefits of enabling CloudTrail for your AWS Lambda serverless functions makes your work more automatic by letting you set up notifications, messages, and alerts that trigger off of configuration events in your AWS account. This means you can react to configuration errors and potential security risks as they are introduced.
Default Value:
By default, CloudTrail data events are not configured
Pre-Requisite:
Sign in as an admin or IAM user with the required permissions
Remediation:
Test Plan:
Sign in to the AWS Management Console
Open the CloudTrail console at https://console.aws.amazon.com/cloudtrail/
Go to Trails, Select the trail you want to examine
Scroll down to find Data events
- If you do not find lambda functions are configured in data events it means lambda API operations are not being recorded by cloud trail.
Using AWS CLI:
aws cloudtrail get-event-selectors --trail-name TrailName
Implementation steps:
Sign in to the AWS Management Console
Open the CloudTrail console at https://console.aws.amazon.com/cloudtrail/
Go to Trails, Select the trail you want to modify
Scroll down you find Data events, click on the edit button
Click on Add data event type
Select the event type as Lambda, and the log selector template has you want
- Click on the Save changes button.
Using AWS CLI:
aws cloudtrail put-event-selectors --trail-name TrailName2 --event-selectors '[{"ReadWriteType": "All","IncludeManagementEvents": true,"DataResources": [{"Type": "AWS::Lambda::Function","Values": ["arn:aws:lambda"]}]'
Backout Plan:
Follow the Implementation steps till 4th step
Click remove button
- click save changes
Using AWS CLI:
aws cloudtrail delete-event-selectors --trail-name TrailName2 --event-selectors '[{"ReadWriteType": "All","IncludeManagementEvents": true,"DataResources": [{"Type": "AWS::Lambda::Function","Values": ["arn:aws:lambda"]}]'
Resources:
https://docs.aws.amazon.com/lambda/latest/dg/logging-using-cloudtrail.html
https://docs.amazonaws.cn/en_us/lambda/latest/dg/with-cloudtrail-example.html