If, for any reason, you need to use the L1 construct I found this documentation to be helpful:
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnLaunchTemplate.html
The reported example is a bit annoying but I tested it and it works:
declare const cluster: eks.Cluster;
const userData = `MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="
--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
echo "Running custom user data script"
--==MYBOUNDARY==--\\
`;
const lt = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', {
launchTemplateData: {
instanceType: 't3.small',
userData: Fn.base64(userData),
},
});
cluster.addNodegroupCapacity('extra-ng', {
launchTemplateSpec: {
id: lt.ref,
version: lt.attrLatestVersionNumber,
},
});