aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(aws-batch-alpha): Add xray as a parameter of batch.ComputeResources

Open gmarchand opened this issue 4 years ago • 3 comments

Description

AWS Xray is not included per default in AWS Batch. We need to add a launch template with a user data script. We could propose this option with a parameter in the batch.ComputeResources object

Use Case

It's not well documented in the AWS documentation, only in a blogpost https://aws.amazon.com/fr/blogs/mt/configure-aws-x-ray-tracing-aws-batch-jobs/#:~:text=AWS%20Batch%20is%20not%20integrated,with%20the%20X%2DRay%20SDK.

Proposed Solution

cdk python

        with open(from_root('cdk','constructs', 'user_data.txt')) as f:
            txt = f.read()

        batch_launch_template = ec2.CfnLaunchTemplate(self,'launch-template',
            launch_template_name = type + '-batch-launch-template',
            launch_template_data = ec2.CfnLaunchTemplate.LaunchTemplateDataProperty(
                user_data=cdk.Fn.base64(txt)
            )
        )
        batch_launch_template_spec = batch.LaunchTemplateSpecification(
            launch_template_name=batch_launch_template.launch_template_name
        )
        compute_environment = batch.ComputeEnvironment(self,
            "batch-compute-environment",
            compute_resources=batch.ComputeResources(
                vpc=ec2_vpc,
                image = ec2_ami,
                instance_types= batch_compute_instancetypes,
                instance_role=batch_compute_env_instanceprofile_arn,
                security_groups=[ec2_vpc_sg],
                vpc_subnets=ec2_vpc_subnets,
                compute_resources_tags={'type':type,'application':'batch-foo'} if fargate_disabled else None,
                type=batch.ComputeResourceType.SPOT if fargate_disabled else batch.ComputeResourceType.FARGATE,
                bid_percentage=90 if fargate_disabled else None,
                launch_template = batch_launch_template_spec if fargate_disabled else None,
            ))

userdata.txt


Content-Type: multipart/mixed; boundary="==XRAYDAEMON=="
MIME-Version: 1.0

--==XRAYDAEMON==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

#!/bin/bash

arch_name="$(uname -m)"
if [ "${arch_name}" = "aarch64" ]; then
    echo "Running aarch64"
    curl https://s3.eu-west-1.amazonaws.com/aws-xray-assets.eu-west-1/xray-daemon/aws-xray-daemon-arm64-3.x.rpm -o /home/ec2-user/xray.rpm
elif [ "${arch_name}" = "arm64" ]; then
    echo "Running arm64"
    curl https://s3.eu-west-1.amazonaws.com/aws-xray-assets.eu-west-1/xray-daemon/aws-xray-daemon-arm64-3.x.rpm -o /home/ec2-user/xray.rpm
else
    echo "Running others archs"
    curl https://s3.eu-west-1.amazonaws.com/aws-xray-assets.eu-west-1/xray-daemon/aws-xray-daemon-3.x.rpm -o /home/ec2-user/xray.rpm
fi
yum install -y /home/ec2-user/xray.rpm
--==XRAYDAEMON==--
```

### Other information

_No response_

### Acknowledge

- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

gmarchand avatar Feb 16 '22 09:02 gmarchand

Any updates on this request?

kellan-cartledge avatar Mar 03 '23 01:03 kellan-cartledge

Batch in CDK now supports launch templates, which allow you to configure user data.

comcalvi avatar Apr 12 '23 17:04 comcalvi

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Apr 12 '23 17:04 github-actions[bot]