https://pulumi.com logo
#general
Title
# general
h

high-jackal-29091

04/15/2020, 8:33 AM
Hey. Either I found a bug or I am doing something wrong. Could you please advise (or should I submit a GH issue)? What am I trying to do is to retrieve an existing aws AMI imageId deployed to the same aws account from which I do request. For some reason when my search query finds AMI, the returned imageId is undefined.
Copy code
const ami = aws.getAmi({
            mostRecent: false,
            owners: ["0123456"], // my AWS account ID
        }, { provider: args.provider });

        let imageId = ami.imageId || ami.id;

        console.log('IMAGE ID: ' + imageId); 
//result: Your query returned more than one result. Please try a more specific search criteria, or set `most_recent` attribute to true.

const ami = aws.getAmi({
            filters: [
                {
                    name: "name",
                    values: ['non existing ami name'],
                }
            ],
            mostRecent: true,
            owners: ["0123456"], // my AWS account ID
        }, { provider: args.provider });

        let imageId = ami.imageId || ami.id;

        console.log('IMAGE ID: ' + imageId); 
// result:  Your query returned no results. Please change your search criteria and try again.

const ami = aws.getAmi({
            mostRecent: true,
            owners: ["0123456"], // my AWS account ID
        }, { provider: args.provider });

        let imageId = ami.imageId || ami.id;

        console.log('IMAGE ID: ' + imageId); 
//result: IMAGE ID: undefined
b

broad-dog-22463

04/15/2020, 12:27 PM
Hi @high-jackal-29091 Can you change your code slightly and export the AMI Id? i.e
export const imageID = imageId;
And tell me if that works?
You may need to change your code to look like the following:
Copy code
const amiId = aws.getAmi({
    owners: ["0123456"],
    mostRecent: true,
}, { async: true }).then(ami => ami.id);
h

high-jackal-29091

04/15/2020, 2:54 PM
Hey Paul, my code is inside
export class ABC
constructor so I could not export const from there. I added imageID: imageId to
this.registerOutputs
but it did not work.
{ async: true }).then(ami => ami.id);
works like a charm.
Thanks lad, cheers!
2 Views