Should the Userdata when launching an ec2 instance always be a String? Cant that be a byte array? Java API: I use ec2Client.runInstance(TEST_IMAGE_ID, instanceType, "USER_DATA");
Asked
Active
Viewed 3,144 times
3
-
Which client library are you using? – Matt Solnit Sep 20 '11 at 22:55
-
Wrapper around basic Java sdk that they give (AWS SDK for Java). – Satish Sep 21 '11 at 00:00
1 Answers
4
According to Amazon:
The user data must be base64 encoded before being submitted to the API. The API command line tools perform the base64 encoding for you. The data is in base64 and is decoded before being presented to the instance.
You need to find out if your Java API will perform this base-64 encoding for you or if you have to do it yourself. [See Matt Solnit's comment below.]
In any case, be careful that you do not exceed the limit of 16KB for user-data.

Eric Hammond
- 22,089
- 5
- 66
- 75
-
2The AWS SDK for Java does _not_ automatically base64-encode, so there you go :-). – Matt Solnit Sep 21 '11 at 19:39
-
1I assume that most users of the AWS SDK for Java do not base-64 encode their simple user-data text they pass in. If that works, then I guess EC2 must return the raw user-data text on the instance if it is not base-64 encoded. This documentation and the actual behavior has never been clear to me. – Eric Hammond Sep 21 '11 at 20:28
-
I had the same thought. I use Typica, which always base64-encodes. I did find [this forum post](https://forums.aws.amazon.com/thread.jspa?messageID=275582) which indicates the AWS SDK may have changed recently: "[we] are trying to upgrade to the latest v1.2.7 (apparently launch config user data now needs to be base64-encoded)" – Matt Solnit Sep 21 '11 at 20:53
-
Thanks everyone!! Helped me to understand it more better! Have one more question.. Did u come across Java API to actually extract the userdata that was sent to the instance while its launch? Actually, i want to test if my instance is launched succesfully along with the userdata.. Thanks!! – Satish Sep 21 '11 at 22:39
-
The API for extracting user-data is simply to request this URL on the instance: http://instance-data/latest/user-data/ – Eric Hammond Jul 03 '12 at 15:31