简体   繁体   中英

Not authorized for images: boto3 error

I am trying to run this script:

from __future__ import print_function

import paramiko
import boto3


#print('Loading function')

paramiko.util.log_to_file("/tmp/Dawny.log")

# List of EC2 variables
region = 'us-east-1'
image = 'ami-<>'
keyname = '<>.pem'

ec2 = boto3.resource('ec2')


instances = ec2.create_instances(
    ImageId=image, MinCount=1, MaxCount=1, 
    InstanceType = 't2.micro', KeyName=keyname)

instance = instances[0]
instance.wait_until_running()

instance.load()

print(instance.public_dns_name)

I am running this script on a server which has all the aws configurations done (in aws configure )

And, when I run it, I get this error:

botocore.exceptions.ClientError: An error occurred (AuthFailure) when calling the RunInstances operation: Not authorized for images: [ami-<>]

Any reason why? And, how do I solve it?

[The image is private. But, as I have configured boto on the server, technically, it shouldn't be a problem, right?]

There is few answer for this error

  1. Insufficient parameter, but create_instance give your other error. eg VPC-id, subnet-ID, Security group are missing.

  2. Your API Access key in credential doesn't have any right to initate run-instance. Please go to IAM and check whether your user are given adequate roles to perform the task.

You might run into this error if you try to use the Key Pair file name instead of the actual name in AWS Console > EC2 > Key Pairs

aws ec2 run-instances --image-id ami-123457916 --instance-type t3.nano 
--key-name **my_ec2_keypair.pem**

Should be name of the KeyPair, not the filename of the KeyPair.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM