Batch and UserData synths ok but fails deploy with: "Operation failed, ComputeEnvironment went INVALID with error: CLIENT_ERROR - Launch Template UserData is not MIME multipart format"
See original GitHub issueThe context for this issue is well described in the Gitter aws-cdk channel over here, along with the tests performed by @skinny85, @reisingerf and myself:
https://gitter.im/awslabs/aws-cdk?at=5e54579d9aeef6523217b25f
Reproduction Steps
Given the following snippet, as described in the Gitter thread:
const vpc = ec2.Vpc.fromLookup(this, 'Vpc', {
isDefault: true,
});
const batch_instance_role = new iam.Role(this, 'BatchInstanceRole', {
roleName: 'UmccriseBatchInstanceRole',
assumedBy: new iam.CompositePrincipal(
new iam.ServicePrincipal('ec2.amazonaws.com'),
new iam.ServicePrincipal('ecs.amazonaws.com'),
),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonEC2RoleforSSM'),
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonEC2ContainerServiceforEC2Role')
],
});
const spotfleet_role = new iam.Role(this, 'AmazonEC2SpotFleetRole', {
assumedBy: new iam.ServicePrincipal('spotfleet.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonEC2SpotFleetTaggingRole'),
],
});
const batch_service_role = new iam.Role(this, 'BatchServiceRole', {
assumedBy: new iam.ServicePrincipal('batch.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSBatchServiceRole'),
],
});
const batch_instance_profile = new iam.CfnInstanceProfile(this, 'BatchInstanceProfile', {
instanceProfileName: 'UmccriseBatchInstanceProfile',
roles: [batch_instance_role.roleName],
});
const launch_template = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', {
launchTemplateData: {
userData: core.Fn.base64(`
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="
--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
echo Hello
--==MYBOUNDARY==--
`),
},
launchTemplateName: 'UmccriseBatchComputeLaunchTemplate',
});
new batch.CfnComputeEnvironment(this, 'UmccriseBatchComputeEnv', {
type: 'MANAGED',
serviceRole: batch_service_role.roleArn,
computeResources: {
type: 'SPOT',
maxvCpus: 128,
minvCpus: 0,
desiredvCpus: 0,
imageId: 'ami-05c621ca32de56e7a',
launchTemplate: {
launchTemplateId: launch_template.ref,
version: launch_template.attrLatestVersionNumber,
},
spotIamFleetRole: spotfleet_role.roleArn,
instanceRole: batch_instance_profile.instanceProfileName!,
instanceTypes: ['optimal'],
subnets: [vpc.publicSubnets[0].subnetId],
securityGroupIds: ['sg-0a5cf974'],
tags: { 'Creator': 'Batch' },
}
});
For more context, there’s this other working example too:
https://github.com/awslabs/aws-batch-helpers/issues/5#issue-425133706
Error Log
This:
Operation failed, ComputeEnvironment went INVALID with error: CLIENT_ERROR - Launch Template UserData is not MIME multipart format
Coupled with the deploy
time error (in Python, ask @skinny85 for the TypeScript counterpart):
6/10 | 10:01:20 AM | UPDATE_FAILED | AWS::Batch::ComputeEnvironment | UmccriseBatchComputeEnv Operation failed, ComputeEnvironment went INVALID with error: CLIENT_ERROR - Launch Template UserData is not MIME multipart format
/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7838:49
\_ Kernel._wrapSandboxCode (/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8298:20)
\_ Kernel._create (/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7838:26)
\_ Kernel.create (/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7585:21)
\_ KernelHost.processRequest (/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7372:28)
\_ KernelHost.run (/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7312:14)
\_ Immediate._onImmediate (/Users/romanvg/.miniconda3/envs/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7315:37)
\_ processImmediate (internal/timers.js:456:21)
Environment
- CLI Version : 1.25.0 (build 5ced526)
- Framework Version: 1.25.0 (build 5ced526)
- OS : MacOS Catalina 10.15.3
- Language : Python and Typescript
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
https://huggingface.co/dbernsohn/roberta-go/commit...
+an ces +} )} +Ġf ind +el l +out il +at form +Ġst ore +pos it +Int erval +U se ... +po licy...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After much playing around I’ve managed to see a workaround for a python deployment. Reading in the user data from a file is better than using a multi-line string.
Part 1: Read in the user data
Part 2: Assign as a Userdata object with the custom method
Part 3: Add to launch_template_data dict
The render magically gets rid of the
lines
attribute in the stack and the base64 re-encodes it as appropriatePart 4: Initialise the launch template
Part 5: Override the launch template property
Adding in userdata in the previous step under the kwarg
launch_template_data
doesn’t seem to work so we override the property using theadd_property_override
insteadPart 6: Validate
Our launch template should look like this after running
cdk synth
@brainstorm - I believe the CLIENT_ERROR issue is in the UserData is to do with whitespace. My advice is to copy exactly one of the examples here: https://docs.aws.amazon.com/batch/latest/userguide/launch-templates.html and just modify the commands, leaving the whitespace exactly the same.