GetAmi
Source:
src/AWS/EC2/GetAmi.ts
The DescribeImages-backed AMI lookup (IAM action ec2:DescribeImages;
Describe* actions do not support resource-level permissions, so the
runtime grant is on *). Returns the newest available image matching the
filters, or undefined when nothing matches.
As a data source, invoke it at plan time via getAmi — the
result is an Output resolved during plan/deploy and inert inside
deployed bundles. As a runtime binding, bind it inside a Function to
look images up at runtime with the IAM grant attached automatically.
Provide the implementation with
Effect.provide(AWS.EC2.GetAmiHttp) (already registered by
AWS.providers() for plan-time use).
Looking Up Images
Section titled “Looking Up Images”Plan-time lookup (data source)
const instance = yield* AWS.EC2.Instance("web", { imageId: AWS.EC2.getAmi({ owners: ["amazon"], name: ["al2023-ami-2023.*"], }).ImageId.as<string>(), instanceType: "t3.micro", subnetId: subnet.subnetId,});Runtime lookup inside a Function
// init — bind the operationconst getAmi = yield* AWS.EC2.GetAmi({ owners: ["amazon"], name: ["al2023-ami-2023.*"],});
// runtime — read the newest matching imageconst latest = yield* getAmi();console.log(latest?.ImageId, latest?.CreationDate);