how to pass in the user-data when launching AWS instances using CLI

前端 未结 2 1269
孤城傲影
孤城傲影 2021-01-05 01:14

I\'m using the AWS CLI to launch instances, and the command is: aws ec2 run-instances

what i\'m expecting is to pass in a script as the user-data. so, I did: DATA=

相关标签:
2条回答
  • 2021-01-05 01:53

    There is no need to base64 encode the data yourself.

    You can prefix a file name/path with file://

    So,

    aws ec2 run-instances --user-data file://my_script
    

    or

    aws ec2 run-instances --user-data file:///full/path/to/my_script
    
    0 讨论(0)
  • 2021-01-05 02:02

    To pass the script as a string, make sure to specify the interpreter as normal prior to your commands. Hitting enter in the open string allows for adding a new line. Ex.:

    $ aws ec2 run-instances --image-id ami-16d4986e --user-data '#!/bin/bash
    > poweroff'
    
    0 讨论(0)
提交回复
热议问题