Home Big Data Run Kinesis Agent on Amazon ECS

Run Kinesis Agent on Amazon ECS

0
Run Kinesis Agent on Amazon ECS

[ad_1]

Kinesis Agent is a standalone Java software program software that gives a simple technique to gather and ship information to Amazon Kinesis Information Streams and Amazon Kinesis Information Firehose. The agent constantly 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 your entire 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 submit describes the steps to ship information from a containerized software to Kinesis Information Firehose utilizing Kinesis Agent. Extra particularly, we present the best way to run Kinesis Agent as a sidecar container for an software operating in Amazon Elastic Container Service (Amazon ECS). After the information is in Kinesis Information Firehose, it may be despatched to any supported vacation spot, equivalent to Amazon Easy Storage Service (Amazon S3).

As a way to current the important thing factors required for this setup, we assume that you’re accustomed to Amazon ECS and dealing with containers. We additionally keep away from the implementation particulars and packaging strategy of our check information technology software, known as the producer.

Resolution 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 through a bind mount in Amazon ECS.

Solution design diagram

Stipulations

You need to fulfill the next conditions for the profitable completion of this activity:

With these conditions in place, you may start subsequent step to bundle a Kinesis Agent and your required agent configuration as a container in your native growth 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 Information Firehose supply stream known 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 should have Kinesis Agent, which and discover binaries, and the Kinesis Agent configuration file that you simply ready earlier. Its entry level should be configured utilizing the start-aws-kinesis-agent script. This command is put in while 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 in an effort to reference it within the subsequent part.

Create an ECS activity definition with Kinesis Agent and the applying container

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

Within the following pattern container definition, we use a bind mount known 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 remember to change taskRoleArn and executionRoleArn to legitimate IAM roles in your AWS account. On this occasion, the IAM position used for taskRoleArn should have write permissions to Kinesis Information Firehose that you simply specified earlier within the agent.json file. Moreover, make it possible for the ECR picture paths and awslogs-region are modified as per your AWS account.

{
    "household": "kinesis-agent-demo",
    "taskRoleArn": "arn:aws:iam::111111111:position/kinesis-agent-demo-task-role",
    "executionRoleArn": "arn:aws:iam::111111111:position/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 activity

Lastly, you may run a brand new ECS activity utilizing the duty definition you simply created utilizing the aws ecs run-task command. When the duty is began, you need to be capable of see two containers operating underneath that activity on the Amazon ECS console.

Amazon ECS console screenshot

Conclusion

This submit 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 submit, you should utilize a Kinesis Agent container in different environments equivalent to Amazon Elastic Kubernetes Service (Amazon EKS).

To study extra about utilizing Kinesis Agent, confer with Writing to Amazon Kinesis Information Streams Utilizing Kinesis Agent. For extra details about Amazon ECS, confer with the Amazon ECS Developer Information.


In regards to the Writer

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 perfect out of their cloud journey.

[ad_2]