How to check whether my user data passing to EC2 instance working or not?

后端 未结 5 1988
再見小時候
再見小時候 2021-01-31 14:23

While creating new AWS EC2 instance using EC2 command line API, i am passing some user data to new instance.

Now how i came to know whether that user data executed or no

5条回答
  •  猫巷女王i
    2021-01-31 14:56

    Eric Hammond suggests:

    Enable logging for your user data

    exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
    

    Take care to put a space between the two > > characters at the beginning of the statement.

    Here’s a complete user-data script as an example:

    #!/bin/bash -ex
    exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
    echo BEGIN
    date '+%Y-%m-%d %H:%M:%S'
    echo END
    
    

    Source: Logging user-data Script Output on EC2 Instances (2010, Hammond)

提交回复
热议问题