Reputation: 410
Is there anyway to use a file when scripting a Launch Config using the cloud formation template? My launch config is far too big for the 4096 character limit. The cli allows this, terraformer allows this, the interface to create a launch configuration also allows this.
Upvotes: 1
Views: 2333
Reputation: 11
Assuming that you can preprocess your bootstrap userdata file on a linux/mac system and call cloudformation via the cli, you can do the following.
First, create multiple parameters in your cloudformation template to accept the input. I call these parameters UserData, UserData2, UserData3 and UserData4.
delete any preexisting 'split' files in the current directory:
rm -f ./xa?
base64 encode your bootstrap script file:
BOOTSTRAP_BASE64_ENC=$(base64 -w0 ${GENERATED_USERDATA_FILE_PATH})
Split the base64 encoded file content into 4096 byte parts:
echo $BOOTSTRAP_BASE64_ENC | split -b 4096
When calling 'aws cloudformation create-stack' pass the split files into the aforementioned parameters:
ParameterKey=UserData,ParameterValue=$(cat xaa) ParameterKey=UserData2,ParameterValue=$(cat xab) ParameterKey=UserData3,ParameterValue=$(cat xac) ParameterKey=UserData4,ParameterValue=$(cat xad)
In the 'Properties' section of your Launchconfig you can reassemble the userdata file from the passed in parameters like so:
"UserData" : { "Fn::Join" : [ "", [ { "Ref" : "UserData" }, { "Ref" : "UserData2" }, { "Ref" : "UserData3" }, { "Ref" : "UserData4" }]]},
Upvotes: 0
Reputation: 410
I have not found a way to specify a userdata file like in other products. However my workaround is to upload the userdata file to s3 and then have the userdata in the template download and run it. Here is the applicable UserData section from my template. This is a powershell example.
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"\n",
[
"<powershell>",
"Read-S3Object -BucketName deployment -Key userdata/user-data.ps1 -File 'c:/temp/userdata.ps1' -Region us-west-2",
"Invoke-Expression 'c:/temp/userdata.ps1'",
"Remove-Item -Recurse -Force C:/temp",
"</powershell>"
]
]
}
}
Upvotes: 1