Ingesting S3 logs via SQS
This page is applicable only if you are using Elastic Agents.
You can analyse and visualise logs stored in Amazon S3 by streaming the data to your Elastic deployment. This can be used for a variety of logs, such as CloudTrail logs.
This guide shows you how to set up an Amazon Simple Queue Service (SQS) for an Amazon S3 bucket and stream its logs into Elastic. The SQS queue is introduced as a buffering mechanism to avoid potential data loss when the Elastic Agent may be down or unavailable. It helps with load balancing, HA (high availability), and disaster recovery.
Architectural setup
Here is an overview of the setup involving Amazon SQS, S3, and Elastic Agents:

- When an event occurs in an S3 bucket, such as a new object being created, S3 can send a message to an SQS queue.
- The Elastic Agent polls SQS for new messages.
- Upon receiving these messages, SQS requests for the respective logs from the S3 bucket.
- The Elastic Agent retrieves the logs, sending it through the VPCE into StackOps Elastic.
Note: SQS does not store the logs. It only serves as a notification system for log creation in the S3 bucket.
Limitations
By using an SQS queue for buffer, past data cannot be streamed into the Elastic deployment. To work around this limitation, you can set up two Elastic Agent integrations:
- An integration for S3 and SQS to read current data.
- An integration directly from S3 to read past data.
You can terminate the latter integration once the data has caught up to the point when you started the S3 and SQS integration.
Tutorial: Ingesting S3 logs via SQS
Here is the high-level overview of the setup process:
- Create an SQS queue to receive messages from S3.
- (Optional) Modify KMS key permissions.
- Create an S3 event notification.
- Grant permissions to the Elastic Agent role in AWS.
- Add Custom AWS Logs integration in Elastic.
Before you begin
Ensure that you have already set up the following resources:
- A StackOps Elastic deployment with its Kibana URL.
- A whitelisted VPC Endpoint between your AWS VPC and StackOps Elastic deployment.
- (If you are using your own key for encryption) AWS KMS key
Step 1: Create an SQS queue
Create an encrypted SQS queue to receive messages. You can use your own KMS key or a managed AWS key for encryption.
To create an SQS queue:
Go to the AWS SQS console.
Select Queues.
Select Create Queue.
Under Details, enter the following details:
- Type—Use
Standard. - Name
- Type—Use
Under Configuration, enter the following details:
Visibility timeout—Set to
910 seconds, in accordance with Elastic documentation.Configure the other settings as required.

Under Access policy, select Advanced.

In the code box, append the following JSON object, making sure to replace all
<PLACEHOLDER_VALUES>with your own values:
{
"Sid": "Allow S3",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": [
"SQS:SendMessage"
],
"Resource": "<SQS_ARN>",
"Condition": {
"ArnLike": {
"aws:SourceArn": "<ARN_OF_YOUR_S3_BUCKET>"
},
"StringEquals": {
"aws:SourceAccount": "<AWS_ACCOUNT_ID>"
}
}
},
{
"Sid": "Allow Elastic Agent",
"Effect": "Allow",
"Principal": {
"AWS": "<ARN_OF_ELASTIC_AGENT>"
},
"Action": [
"SQS:ReceiveMessage",
"SQS:DeleteMessage"
],
"Resource": "<SQS_ARN>"
}Note: <ARN_OF_ELASTIC_AGENT> refers to the Role/User used by Elastic Agent.
Under Encryption, enable server-side encryption.
Select the Encryption key type.
- Amazon SQS key (SSE-SQS) — Select this if you are using a managed key.
- AWS Key Management Service key (SSE-KMS) — Select this if you are using your own KMS key.
(If using SSE-KMS) Select the required Customer master key.

Select Create queue to finalise.
Step 2: Set up KMS key permissions (Optional)
If you are using own KMS key, you must modify the key policy to set up key permissions. If you are using an Amazon SQS key, you can skip this step as you do not need to manage the key policy.
The key policy will assign the required permissions to SQS, S3 and Elastic Agent so that they can use this key to decrypt and encrypt data.
To set up KMS key permissions:
Go to the AWS KMS console.
In the left sidebar, select Customer-managed keys.
From the list of keys, select the alias or key ID of the KMS key you are using.
Under Key policy, select Edit.

In the code box, append the following JSON object, making sure to replace all
<PLACEHOLDER_VALUES>with your own values:{ "Sid": "Allow use of the key", "Effect": "Allow", "Principal": { "AWS": "<ARN_OF_ELASTIC_AGENT>" }, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey" ], "Resource": "*" }, { "Sid": "POC SQS", "Effect": "Allow", "Principal": { "Service": "sqs.amazonaws.com" }, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey" ], "Resource": "*" }, { "Sid": "POC S3", "Effect": "Allow", "Principal": { "Service": "s3.amazonaws.com" }, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey" ], "Resource": "*" }Note:
<ARN_OF_ELASTIC_AGENT>refers to the Role/User used by Elastic Agent.Select Save changes to finalise.
Step 3: Create an S3 event notification
Prerequisites:
- An S3 bucket.
You must create an event notification on your S3 bucket to push events to SQS.
To create an S3 bucket event notification:
Go to the AWS S3 console.
In the left sidebar, select Buckets.
From the list of buckets, select the relevant S3 bucket.
Go to the Properties tab.

Under Event notifications, select Create event notification.

Under General configuration, enter the following details:
Event name
Prefix—If you only want to ingest some data from the S3 bucket into Elastic, specify the particular folder from which you want to ingest data. Otherwise, leave this field empty.

Under Event types, select All object create events.
Under Destination, select SQS queue.
Select the SQS queue you created in Step 1.

Click Save changes to finalise.

After creating the event notification, you should be able to see new events being sent to SQS queue by polling the SQS queue.
Note: Past data cannot be read using S3 with SQS.
Step 4: Grant permissions for Elastic Agent role
To read SQS messages, the IAM identity (Role/User) used by Elastic Agent to connect to AWS must have the required permissions.
To grant permissions to the Elastic Agent role:
- Go to AWS IAM console.
- (Depending on the IAM identity type) Go Access management > Roles or Users.
- Select the IAM identity used by Elastic Agent.
- Under Permissions, select Add permissions > Create inline policy.
- Select JSON and enter the necessary permissions policy. Here is an example policy:
{ "Statement": [ { "Sid": "AssumeIntegrationRole", "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "arn:aws:iam::<ACCOUNT_ID>:role/<ROLE_NAME>" }, { "Sid": "AWSIntegration", "Effect": "Allow", "Action": [ "tag:GetResources", "sts:GetCallerIdentity", "sqs:ReceiveMessage", "sqs:ListQueues", "sqs:DeleteMessage", "sqs:ChangeMessageVisibility", "sns:ListTopics", "s3:GetObject", "s3:GetBucketLocation", "kms:Decrypt", / include only if you are using KMS keys "rds:ListTagsForResource", "rds:DescribeDBInstances", "logs:FilterLogEvents", "iam:ListAccountAliases", "ec2:DescribeRegions", "ec2:DescribeInstances", "cloudwatch:GetMetricData", "cloudwatch:ListMetrics" ], "Resource": "*" } ], "Version": "2012-10-17" } - Enter a Name for the policy.
- Select Create policy.
- Confirm that the inline policy is attached to the selected role/user.
Step 5: Add Custom AWS integration in Elastic
Add the Custom AWS Logs integration to your Elastic Agents to begin ingesting S3 logs in Elasticsearch. If you need to filter the logs for ingestion, you can set the integration to read data from a specific folder in the S3 bucket.
Note: All SQS messages will be consumed by Elastic Agent, regardless of whether the event message fits the criteria set in the integration.
To add Custom AWS Logs integration:
- In Kibana, go to Management > Fleet.
- Select Agent policies.
- Select or create the policy that you want to add the integration to.
- Select Add integration.
- Search for and select
Custom AWS Logs. - Select Add Custom AWS Logs to enable the integration.
- In Integration settings, provide the following details:
- Integration name—Use an easily-identifiable name.
- Description
- Select Collect Logs from S3 Bucket > AWS logs from S3.
- Queue URL
- (Optional) Advanced Settings > File Selectors—Use regex to specify the folder path of the object in the S3 bucket.

- Select Save and continue > Save and deploy changes.