Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:17:57+00:00 2026-06-04T11:17:57+00:00

Is there a way with the boto python API to specify tags when creating

  • 0

Is there a way with the boto python API to specify tags when creating an instance? I’m trying to avoid having to create an instance, fetch it and then add tags. It would be much easier to have the instance either pre-configured to have certain tags or to specify tags when I execute the following command:

ec2server.create_instance(
        ec2_conn, ami_name, security_group, instance_type_name, key_pair_name, user_data
    )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:17:59+00:00Added an answer on June 4, 2026 at 11:17 am

    This answer was accurate at the time it was written but is now out of date. The AWS API’s and Libraries (such as boto3) can now take a “TagSpecification” parameter that allows you to specify tags when running the “create_instances” call.


    Tags cannot be made until the instance has been created. Even though the function is called create_instance, what it’s really doing is reserving and instance. Then that instance may or may not be launched. (Usually it is, but sometimes…)

    So, you cannot add a tag until it’s been launched. And there’s no way to tell if it’s been launched without polling for it. Like so:

    reservation = conn.run_instances( ... )
    
    # NOTE: this isn't ideal, and assumes you're reserving one instance. Use a for loop, ideally.
    instance = reservation.instances[0]
    
    # Check up on its status every so often
    status = instance.update()
    while status == 'pending':
        time.sleep(10)
        status = instance.update()
    
    if status == 'running':
        instance.add_tag("Name","{{INSERT NAME}}")
    else:
        print('Instance status: ' + status)
        return None
    
    # Now that the status is running, it's not yet launched. The only way to tell if it's fully up is to try to SSH in.
    if status == "running":
        retry = True
        while retry:
            try:
                # SSH into the box here. I personally use fabric
                retry = False
            except:
                time.sleep(10)
    
    # If we've reached this point, the instance is up and running, and we can SSH and do as we will with it. Or, there never was an instance to begin with.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to start / stop an Amazon EC2 instance from Google
Is there way of creating empty .mo file? Usually when starting new project I
Is there way in MySQL to create DATETIME from a given attribute of type
Is there way to insert images through the google spreadsheet api? I've looked at
Is there way in MySQL to prevent someone from creating tables and/or databases with
I'm using the Python library boto to connect to Amazon S3 and create buckets
Is there way to automatically maximize the output window on hitting build and then
is there way how to get name ov event from Lambda expression like with
Is there way to better identify design pattern in source codes, esp. if you
Is there way to mute an audio stream or at least control the volume?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.