aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.09k stars 4.01k forks source link

ec2 modify-instance-attribute not working with binary file (fileb://) #8725

Closed brickZA closed 3 weeks ago

brickZA commented 3 weeks ago

Describe the bug

When trying to modify an ec2 instance's user-data with binary data using the fileb:// prefix parameter validation fails.

E.g. calling with the file:// prefix results in a seeming helpful error message:

/usr/local/bin/aws --region eu-west-1   ec2 modify-instance-attribute --instance-id i-06e546e2355651587 --attribute userData --value file://userdata.sh.gz

Error parsing parameter '--value': Unable to load paramfile (userdata.sh.gz), text contents could not be decoded.  If this is a binary file, please use the fileb:// prefix instead of the file:// prefix.

but following the suggestion does not work.

Expected Behavior

The binary file should be properly interpreted and set as the user-data for the ec2 instance.

Current Behavior

$ /usr/local/bin/aws --region eu-west-1   ec2 modify-instance-attribute --instance-id i-06e546e2355651587 --attribute userData --value fileb://userdata.sh.gz

Parameter validation failed:
Invalid type for parameter Value, value: b"\x1f\x8b\<REDACTED>\x00", type: <class 'bytes'>, valid types: <class 'str'>

Reproduction Steps

See current behaviour.

Possible Solution

No response

Additional Information/Context

No response

CLI version used

aws-cli/2.16.1 Python/3.11.8 Linux/6.5.0-35-lowlatency exe/x86_64.ubuntu.22

Environment details (OS name and version, etc.)

Ubuntu 22.04

tim-finnigan commented 3 weeks ago

Thanks for reaching out. The ec2 modify-instance-attribute command (and underlying API) require --value to be a string:

image

If you base64 encode your string then this will work:

aws ec2 modify-instance-attribute --instance-id i-072f97fe523412345 --attribute userData --value "$(cat userdata.sh.gz | base64)"

And to verify you can run:

aws ec2 describe-instance-attribute --instance-id i-072f97fe523412345 --attribute userData

Which returns:

{
    "InstanceId": "i-072f97fe523412345",
    "UserData": {
        "Value": "H4sICC7eYWYAA3VzZXJkYXRhLnNoAFNW1E/KzNNPSizO4EpNzshXUArJyCxWAKJEheLE3IKcVIXS4tQi3ZTEEqBAclFmQYmeEgCtxpQgNQAAAA=="
    }
}

And then you can decode it:

echo "JVNIQkFTSENPTU1BTkQKZWNobyAiVGhpcyBpcyBhIHNhbXBsZSB1c2VyLWRhdGEgc2NyaXB0LiIK" | base64 --decode
github-actions[bot] commented 3 weeks ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.