skip to Main Content

I am using a module to create an autoscaling group that spins up instances and provides them a launch script to run. The launch script is relatively simple, just a few apt gets/installs, create a user, and write some files. The issue is that one of the files we are writing, is over 600 lines. This ends with the error Error: expected length of user_data to be in the range (1 - 16384), got #!/bin/bash then the entire launch script.

We write the files by piping them through cat, i.e.

cat > example.txt <<EOF

This is an example

EOF

I’m fairly confident that this is due to the launch script being too large. The max for aws seems to be 16kb, while mine is currently 20kb. Do any of you know a way to resolve this issue? I’m unable to put the file into an s3 bucket and grab from the bucket during the launch script, which I believe is one option.

2

Answers


  1. You could have the file in your VCS such as git. Then you can clone or check out the repo in your user data. Of course this implies you have the proper access to your VCS on your image & if you are using a custom AMI, then you can just have the file baked into your AMI & when it spins up you can run whatever else you need in your launch script.

    Login or Signup to reply.
  2. You can use zipped userdata:

    resource "aws_instance" "example" {
      ami           = "ami-xxx"
    ...
      user_data = base64gzip("#!/bin/bashnecho 'Hello, World!' | tee /tmp/hello-world.txt")
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search