How to send UserData for an EC2 instance



I’m trying to use the resource section to include a CloudFormation setup for a custom EC2 configuration. Yeah, I know, it’s not serverless. Sue me, we can’t always do things the way we want to.

Question is: How do I specify the UserData script for the EC2 instance without having the serverless framework try to interpret any variable declarations in there (it’s a Bash script).

Any clues?


In case anyone finds this and wants to know how, here’s what I did:

You can use the ‘UserData’ property when defining an EC2 instance in serverless.yml to send the user data. The value of that property can be a file using the ${file(myfile.txt)} syntax.

However, the contents of the file sent have to be base64 encoded because you’re using the bare cloudformation syntax, not serverless syntax.

So, that’s OK. Build a script. Let’s call it “”. You can fill it with whatever you need.
Then, base64 encode it using your favorite command line tool into a new file, maybe called “”.

Now, in the UserData property, use this: “${file(}” and you should get the intended result.