# Trying to get aws instance id

**URL:** <https://forum.ansible.com/t/trying-to-get-aws-instance-id/20495>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [February 9, 2016, 3:07pm UTC](https://forum.ansible.com/t/trying-to-get-aws-instance-id/20495 "2016-02-09T15:07:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Del\_Pino](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Christian\_Del\_Pino](https://forum.ansible.com/u/Christian_Del_Pino)\
**Post date:** [February 9, 2016, 3:07pm UTC](https://forum.ansible.com/t/trying-to-get-aws-instance-id/20495/1 "2016-02-09T15:07:36Z")

</div>

Hello,

I am having some difficulties trying to obtain the instance id for an ec2 instance that is being created. Here is what I have at the moment to create the ec2 instance:

### Create NAT Instance

- name: Launch NAT instance  
ec2:  
vpc\_subnet\_id: “{{ name\_subnet.subnet.id }}”  
region: “{{ aws\_region }}”  
keypair: “{{ keypair.key.name }}”  
group\_id: “{{ natsecuritygroup.group\_id }}”  
image: “{{ nat\_aws\_image }}”  
instance\_type: “{{ nat\_aws\_instance\_type }}”  
instance\_tags:  
type: “nat”  
Name: “NAT”  
exact\_count: 1  
count\_tag:  
type: “nat”  
Name: “NAT”  
wait: yes  
register: nat  
tags:
- vpcsetup

I am trying to get the instance id from the registered value nat. Here is what I get when I debug the nat variable:

ok: [localhost] =\> {  
“nat”: {  
“changed”: false,  
“instance\_ids”: null,  
“instances”: ,  
“tagged\_instances”: [  
{  
“ami\_launch\_index”: “0”,  
“architecture”: “x86\_64”,  
“block\_device\_mapping”: {  
“/dev/xvda”: {  
“delete\_on\_termination”: true,  
“status”: “attached”,  
“volume\_id”: “vol-xxxxxx”  
}  
},  
“dns\_name”: “[ec2-xxxxxxx.compute-1.amazonaws.com](http://ec2-xxxxxxx.compute-1.amazonaws.com)”,  
“ebs\_optimized”: false,  
“groups”: {  
“sg-xxxxxx”: “nat-sg”  
},  
“hypervisor”: “xen”,  
“id”: “i-xxxxxxxxxxxxxxxx”,  
“image\_id”: “ami-xxxxxxxxx”,  
“instance\_type”: “m4.large”,  
“kernel”: null,  
“key\_name”: “kp”,  
“launch\_time”: “2016-02-09T04:42:36.000Z”,  
“placement”: “us-east-1a”,  
“private\_dns\_name”: “ip-xxxxx.ec2.internal”,  
“private\_ip”: “xxxxx”,  
“public\_dns\_name”: “[ec2-xxxxx.compute-1.amazonaws.com](http://ec2-xxxxx.compute-1.amazonaws.com)”,  
“public\_ip”: “xxxxxx”,  
“ramdisk”: null,  
“region”: “us-east-1”,  
“root\_device\_name”: “/dev/xvda”,  
“root\_device\_type”: “ebs”,  
“state”: “running”,  
“state\_code”: 16,  
“tags”: {  
“Name”: “NAT”,  
“type”: “nat”  
},  
“tenancy”: “default”,  
“virtualization\_type”: “hvm”  
}  
]  
}  
}

I see that the instance\_ids is set to null, but there is a value for id. How do I get the id value? I tried several variations to get the value, but no luck. I keep getting an error saying either:

{“failed”: true, “msg”: “ERROR! ‘list object’ has no attribute ‘id’”}

or

{“failed”: true, “msg”: “ERROR! ‘dict object’ has no attribute ‘id’”}

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 9, 2016, 6:29pm UTC](https://forum.ansible.com/t/trying-to-get-aws-instance-id/20495/2 "2016-02-09T18:29:42Z")

</div>

```auto
 - name: Wait for SSH to come up
   debug: 
      msg: "{{ item.id }}" 
   with_items: nat.instances

```
