Thursday, November 7, 2024

Run Kinesis Agent on Amazon ECS

Kinesis Agent is a standalone Java software program software that provides a simple method to acquire and ship information to Amazon Kinesis Knowledge Streams and Amazon Kinesis Knowledge Firehose. The agent repeatedly displays a set of information and sends new information to the specified vacation spot. The agent handles file rotation, checkpointing, and retry upon failures. It delivers all your information in a dependable, well timed, and easy method. It additionally emits Amazon CloudWatch metrics that can assist you higher monitor and troubleshoot the streaming course of.

This put up describes the steps to ship information from a containerized software to Kinesis Knowledge Firehose utilizing Kinesis Agent. Extra particularly, we present the best way to run Kinesis Agent as a sidecar container for an software working in Amazon Elastic Container Service (Amazon ECS). After the information is in Kinesis Knowledge Firehose, it may be despatched to any supported vacation spot, corresponding to Amazon Easy Storage Service (Amazon S3).

With a purpose to current the important thing factors required for this setup, we assume that you’re acquainted with Amazon ECS and dealing with containers. We additionally keep away from the implementation particulars and packaging strategy of our take a look at information era software, known as the producer.

Answer overview

As depicted within the following determine, we configure a Kinesis Agent container as a sidecar that may learn information created by the producer container. On this occasion, the producer and Kinesis Agent containers share information by way of a bind mount in Amazon ECS.

Solution design diagram

Stipulations

It’s best to fulfill the next stipulations for the profitable completion of this process:

With these stipulations in place, you possibly can start subsequent step to bundle a Kinesis Agent and your required agent configuration as a container in your native improvement machine.

Create a Kinesis Agent configuration file

We use the Kinesis Agent configuration file to configure the supply and vacation spot, amongst different information switch settings. The next code makes use of the minimal configuration required to learn the contents of information matching /var/log/producer/*.log and publish them to a Kinesis Knowledge Firehose supply stream referred to as kinesis-agent-demo:

{
    "firehose.endpoint": "firehose.ap-southeast-2.amazonaws.com",
    "flows": [
        {
            "deliveryStream": "kinesis-agent-demo",
            "filePattern": "/var/log/producer/*.log"
        }
    ]
}

Create a container picture for Kinesis Agent

To deploy Kinesis Agent as a sidecar in Amazon ECS, you first need to bundle it as a container picture. The container will need to have Kinesis Agent, which and discover binaries, and the Kinesis Agent configuration file that you just ready earlier. Its entry level should be configured utilizing the start-aws-kinesis-agent script. This command is put in once you run the yum set up aws-kinesis-agent step. The ensuing Dockerfile ought to look as follows:

FROM amazonlinux

RUN yum set up -y aws-kinesis-agent which findutils
COPY agent.json /and so on/aws-kinesis/agent.json

CMD ["start-aws-kinesis-agent"]

Run the docker construct command to construct this container:

docker construct -t kinesis-agent .

After the picture is constructed, it must be pushed to a container registry like Amazon ECR so as to reference it within the subsequent part.

Create an ECS process definition with Kinesis Agent and the appliance container

Now that you’ve got Kinesis Agent packaged as a container picture, you should utilize it in your ECS process definitions to run as sidecar. To try this, you create an ECS process definition along with your software container (referred to as producer) and Kinesis Agent container. All containers in a process definition are scheduled on the identical container host and due to this fact can share sources corresponding to bind mounts.

Within the following pattern container definition, we use a bind mount referred to as logs_dir to share a listing between the producer container and kinesis-agent container.

You need to use the next template as a place to begin, however make sure you change taskRoleArn and executionRoleArn to legitimate IAM roles in your AWS account. On this occasion, the IAM function used for taskRoleArn will need to have write permissions to Kinesis Knowledge Firehose that you just specified earlier within the agent.json file. Moreover, guarantee that the ECR picture paths and awslogs-region are modified as per your AWS account.

{
    "household": "kinesis-agent-demo",
    "taskRoleArn": "arn:aws:iam::111111111:function/kinesis-agent-demo-task-role",
    "executionRoleArn": "arn:aws:iam::111111111:function/kinesis-agent-test",
    "networkMode": "awsvpc",
    "containerDefinitions": [
        {
            "name": "producer",
            "image": "111111111.dkr.ecr.ap-southeast-2.amazonaws.com/producer:latest",
            "cpu": 1024,
            "memory": 2048,
            "essential": true,
            "command": [
                "-output",
                "/var/log/producer/test.log"
            ],
            "mountPoints": [
                {
                    "sourceVolume": "logs_dir",
                    "containerPath": "/var/log/producer",
                    "readOnly": false
                }
            ],
            "logConfiguration": {
                "logDriver": "awslogs",
                "choices": {
                    "awslogs-create-group": "true",
                    "awslogs-group": "producer",
                    "awslogs-stream-prefix": "producer",
                    "awslogs-region": "ap-southeast-2"
                }
            }
        },
        {
            "title": "kinesis-agent",
            "picture": "111111111.dkr.ecr.ap-southeast-2.amazonaws.com/kinesis-agent:newest",
            "cpu": 1024,
            "reminiscence": 2048,
            "important": true,
            "mountPoints": [
                {
                    "sourceVolume": "logs_dir",
                    "containerPath": "/var/log/producer",
                    "readOnly": true
                }
            ],
            "logConfiguration": {
                "logDriver": "awslogs",
                "choices": {
                    "awslogs-create-group": "true",
                    "awslogs-group": "kinesis-agent",
                    "awslogs-stream-prefix": "kinesis-agent",
                    "awslogs-region": "ap-southeast-2"
                }
            }
        }
    ],
    "volumes": [
        {
            "name": "logs_dir"
        }
    ],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "cpu": "2048",
    "reminiscence": "4096"
}

Register the duty definition with the next command:

aws ecs register-task-definition --cli-input-json file://./task-definition.json

Run a brand new ECS process

Lastly, you possibly can run a brand new ECS process utilizing the duty definition you simply created utilizing the aws ecs run-task command. When the duty is began, you must be capable to see two containers working beneath that process on the Amazon ECS console.

Amazon ECS console screenshot

Conclusion

This put up confirmed how easy it’s to run Kinesis Agent in a containerized setting. Though we used Amazon ECS as our container orchestration service on this put up, you should utilize a Kinesis Agent container in different environments corresponding to Amazon Elastic Kubernetes Service (Amazon EKS).

To be taught extra about utilizing Kinesis Agent, check with Writing to Amazon Kinesis Knowledge Streams Utilizing Kinesis Agent. For extra details about Amazon ECS, check with the Amazon ECS Developer Information.


In regards to the Creator

Buddhike de Silva is a Senior Specialist Options Architect at Amazon Net Companies. Buddhike helps prospects run massive scale streaming analytics workloads on AWS and make the most effective out of their cloud journey.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles