Closed munjalpatel closed 1 year ago
This is my sample code. And the ImageId seems to be ami-005e79c34846da0a4
. Is this something you are looking for?
import {
App, Stack, StackProps, CfnOutput,
aws_ec2 as ec2,
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const lookupImage = new ec2.LookupMachineImage({
name: 'fck-nat-amzn2-hvm-*-arm64-ebs',
owners: ['568608671756'],
});
new CfnOutput(this, 'ImageId', { value: lookupImage.getImage(this).imageId });
}
}
// for development, use account/region from cdk cli
const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};
const app = new App();
new MyStack(app, 'test-dev', { env: devEnv });
app.synth();
Outputs [+] Output ImageId ImageId: {"Value":"ami-005e79c34846da0a4"}
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
@pahud, thanks for the help!
If I run stack using npm run cdk deploy
it seems to be working fine.
However, I am integrating AWS CDK in another project and need to run it using regular node-ts
, and that's when it seems to be failing.
@munjalpatel I'm afraid you can't get the imageId simply by this in an async function:
const image = machineImage.getImage(this)
console.log(image)
You should only reference it rather than console.log() it otherwise you will get the default dummy value: https://github.com/aws/aws-cdk/blob/cea1039e3664fdfa89c6f00cdaeb1a0185a12678/packages/%40aws-cdk/aws-ec2/lib/machine-image.ts#L662
This doesn't seem to be a valid bug but it might be a good topic for discussion about your use case. I am closing this issue for now but if you are interested to discuss more about your use case using async func in CDK, feel free to create a separate topic in discussions. Thanks!
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Describe the bug
I am trying to look up an image with
fck-nat-amzn2-hvm-*-arm64-ebs
asname
. I have verified that the image from owner568608671756
exists in my regionus-west-2
.But
new ec2.LookupMachineImage(...)
always return the dummyami-1234
Expected Behavior
An image object for the
fck-nat-amzn2-hvm-1.2.0-20220812-arm64-ebs
image withami-005e79c34846da0a4
should be returned.Current Behavior
An image object for the dummy image with
ami-1234
is returned.Reproduction Steps
test.ts
Run this:
Output:
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.50.0 (build 4c11af6)
Framework Version
No response
Node.js Version
v16.13.2
OS
MacOS Ventura 13.0 (22A380)
Language
Typescript
Language Version
No response
Other information
No response