# AWS KeyPair Error

**URL:** <https://forum.ansible.com/t/aws-keypair-error/18975>\
**Category:** Ansible Developer\
**Tags:** aws\
**Created:** [August 9, 2015, 2:07am UTC](https://forum.ansible.com/t/aws-keypair-error/18975 "2015-08-09T02:07:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Monosij\_Dutta-Roy](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@Monosij\_Dutta-Roy](https://forum.ansible.com/u/Monosij_Dutta-Roy)\
**Post date:** [August 9, 2015, 2:07am UTC](https://forum.ansible.com/t/aws-keypair-error/18975/1 "2015-08-09T02:07:08Z")

</div>

I am getting the following error for AWS Keypair, **generated at AWS and pem file downloaded** , from boto 2.34, on Ubun 15.04.

I have checked that key is for the region (us-east-1) that I am running the playbook for.

Do not understand why it gives the ‘Length exceeds maximum of 2048’ error as key was generated at AWS.

…

vars:  
region: us-east-1  
instance\_type: t2.micro  
count: 3  
tasks:

- name: ec2 keypair  
ec2\_key: name=mykey key\_material=“{{ item }}” region={{ region }}  
with\_file: ~/.ssh/HelloWorld.pem

…

Traceback (most recent call last):  
File “/home/monosij/.ansible/tmp/ansible-tmp-1439084212.68-170231526352889/ec2\_key”, line 2032, in   
main()  
File “/home/monosij/.ansible/tmp/ansible-tmp-1439084212.68-170231526352889/ec2\_key”, line 197, in main  
key = ec2.import\_key\_pair(name, key\_material)  
File “/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py”, line 2924, in import\_key\_pair  
return self.get\_object(‘ImportKeyPair’, params, KeyPair, verb=‘POST’)  
File “/usr/local/lib/python2.7/dist-packages/boto/connection.py”, line 1208, in get\_object  
raise self.ResponseError(response.status, response.reason, body)  
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request

\<?xml version="1.0" encoding="UTF-8"?\>

`InvalidParameterValue`Value (…) for parameter PublicKeyMaterial is invalid. **Length exceeds maximum of 2048**.609a75cd-5e25-403c-ad06-b546d8d6ffb2

FATAL: all hosts have already failed – aborting

…

Thank you for your suggestions.

Mono

---

<div class="post-metadata">

**Author:** ![andy2](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@andy2](https://forum.ansible.com/u/andy2)\
**Post date:** [August 10, 2015, 10:36pm UTC](https://forum.ansible.com/t/aws-keypair-error/18975/2 "2015-08-10T22:36:25Z")

</div>

When you create the key with the AWS console, the .pem file you’ve downloaded is a private key.

The ec2\_key module is for uploading a public key that you generated yourself.

e.g. the public key that’s generated alongside a private key by ssh-keygen.

(This us useful as that you can use the same keypair in different regions or accounts.)

Andy

---

<div class="post-metadata">

**Author:** ![Jim\_Rippon](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@Jim\_Rippon](https://forum.ansible.com/u/Jim_Rippon)\
**Post date:** [August 10, 2015, 10:54pm UTC](https://forum.ansible.com/t/aws-keypair-error/18975/3 "2015-08-10T22:54:40Z")

</div>

Mono,

You can download the public key from the instance you created by logging in as the user AWS created for you {ubuntu or ec2-user for example} and copying it from ~/.ssh/authorized\_keys (either copy-and-paste or using scp)

HTH

Jim

---

<div class="post-metadata">

**Author:** ![Monosij\_Dutta-Roy](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@Monosij\_Dutta-Roy](https://forum.ansible.com/u/Monosij_Dutta-Roy)\
**Post date:** [August 13, 2015, 4:01am UTC](https://forum.ansible.com/t/aws-keypair-error/18975/4 "2015-08-13T04:01:56Z")

</div>

Thanks Jim. Worked out great. I did not realize I had to extract the public key from the pem file separately.

Mono
