How to pass environment variables when programmatically starting a new Amazon EC2 from image?

后端 未结 3 863
陌清茗
陌清茗 2021-01-31 18:34

I am using AWS Java API RunInstance() to start a new EC2 instance from my custom AMI image. How do I pass environment variables to the new EC2 INSTANCE such as database url,

3条回答
  •  失恋的感觉
    2021-01-31 19:34

    You can also use instance metadata retrieval as explained at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html

    From the above document, the following GET request would retrieve user data for an instance if you run it from within the instance:

    GET http://169.254.169.254/latest/user-data
    

    This way, user data can be retrieved dynamically even after the instance is already started and running.

提交回复
热议问题