Skip to content

Instantly share code, notes, and snippets.

@Halliax
Last active January 10, 2020 21:49
Show Gist options
  • Select an option

  • Save Halliax/9c48015812220db80fcc1a85b0727cd7 to your computer and use it in GitHub Desktop.

Select an option

Save Halliax/9c48015812220db80fcc1a85b0727cd7 to your computer and use it in GitHub Desktop.
A section of an EC2 launch template demonstrating usage of the AMI bootstrap.sh script
Parameters:
...
BootstrapArgumentsForSpotFleet:
Description: Arguments to pass to the bootstrap script. See files/bootstrap.sh in https://github.com/awslabs/amazon-eks-ami
Type: String
Default: "--kubelet-extra-args '--node-labels=lifecycle=Ec2Spot,nvidia.com/gpu=true,k8s.amazonaws.com/accelerator=nvidia-tesla
--register-with-taints=spotInstance=true:PreferNoSchedule,nvidia.com/gpu=true:NoSchedule'"
...
...
Resources:
...
NodeLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: !Sub "eksLaunchTemplate-${AWS::StackName}"
LaunchTemplateData:
...
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
set -o xtrace
iid=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
export AWS_DEFAULT_REGION=${AWS::Region}
ilc=`aws ec2 describe-instances --instance-ids $iid --query 'Reservations[0].Instances[0].InstanceLifecycle' --output text`
if [ "$ilc" == "spot" ]; then
/etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArgumentsForSpotFleet}
else
/etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArgumentsForOnDemand}
fi
logid=`aws ec2 describe-tags --filters "Name=resource-id,Values=$iid" "Name=key,Values=aws:cloudformation:logical-id" --region ${AWS::Region} --output=text | cut -f5`
/opt/aws/bin/cfn-signal --exit-code $? \
--stack ${AWS::StackName} \
--resource $logid \
--region ${AWS::Region}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment