title: Using Python to Manage AWS
body: <p>I’m trying to use Python to create EC2 instances but I keep getting these errors. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>#!/usr/bin/env python
  import boto3
  ec2 = boto3.resource('ec2')
  instance = ec2.create_instances(
      ImageId='ami-0922553b7b0369273',
      MinCount=1,
      MaxCount=1,
      InstanceType='t2.micro')
  print instance[0].id
  </code></pre>
  
  <p>Here are the errors I'm getting </p>
  
  <pre><code>Traceback (most recent call last):
    File "./createinstance.py", line 8, in &lt;module&gt;
      InstanceType='t2.micro')
    File "/usr/lib/python2.7/site-packages/boto3/resources/factory.py", line 520, in do_action
      response = action(self, *args, **kwargs)
    File "/usr/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
      response = getattr(parent.meta.client, operation_name)(**params)
    File "/usr/lib/python2.7/site-packages/botocore/client.py", line 320, in _api_call
      return self._make_api_call(operation_name, kwargs)
    File "/usr/lib/python2.7/site-packages/botocore/client.py", line 623, in _make_api_call
      raise error_class(parsed_response, operation_name)
  botocore.exceptions.ClientError: An error occurred (InvalidAMIID.NotFound) when calling the RunInstances operation: The image id '[ami-0922553b7b0369273]' does not exist
  </code></pre>
  
  <p>I also get an error when trying to create a key pair</p>
  
  <p>Here's my code for creating the keypair</p>
  
  <pre><code>  import boto3
  ec2 = boto3.resource('ec2')
  
  # create a file to store the key locally
  outfile = open('ec2-keypair.pem','w')
  
  # call the boto ec2 function to create a key pair
  key_pair = ec2.create_key_pair(KeyName='ec2-keypair')
  
  # capture the key and store it in a file
  KeyPairOut = str(key_pair.key_material)
  print(KeyPairOut)
  outfile.write(KeyPairOut)
  
  response = ec2.instance-describe()
  print response
  </code></pre>
  
  <p>Here's are the error messages</p>
  
  <pre><code>./createkey.py: line 1: import: command not found
  ./createkey.py: line 2: syntax error near unexpected token `('
  ./createkey.py: line 2: `ec2 = boto3.resource('ec2')'
  </code></pre>
  
  <p>What I am I missing?</p>