EC2 · Compute

AMI

Create and track Amazon Machine Images.

Generic driverUniform lifecycle
Scope
Regional
Spec fields
6
Outputs
8
Lookup
Supported

Resource definition

What this resource looks like

This is the CUE shape a Praxis template uses to declare a AMI. The resource key is local to the template; metadata.name supplies its stable Praxis identity.

CUE example
resources: {
  goldenAmi: {
  	apiVersion: "praxis.io/alpha"
  	kind:       "AMI"
  	metadata: name: "\(_naming.prefix)-golden"
  	spec: {
  		region:      _naming.region
  		description: "Golden AMI for \(_naming.prefix) app servers"
  		source: fromAMI: {
  			sourceImageId: variables.imageId
  			encrypted:     true
  		}
  		tags: #AppTags & {purpose: "golden-ami"}
  	}
  }
}

Excerpted from examples/stacks/end-to-end.cue. Open the complete example for its variables and related resources.

Complete examples in the repository

Desired state

Configuration

The spec block accepts 6 fields. 3 are required by the schema; fields with defaults can be omitted.

regionRequired

Region.

string
String
descriptionOptional

Description.

string
String
sourceRequired

Source.

{ fromSnapshot?: { snapshotId: string architecture: "x86_64" | "arm64" | *"x86_64" virtualizationType: "hvm" | *"hvm" rootDeviceName: string | *"/dev/xvda" volumeType: "gp2" | "gp3" | "io1" | "io2" | *"gp3" volumeSize?: int & >0 enaSupport?: bool | *true } fromAMI?: { sourceImageId: string sourceRegion?: string encrypted?: bool kmsKeyId?: string } }
Object
launchPermissionsOptional

Launch Permissions.

{ accountIds?: [...string] public?: bool }
Object
deprecationOptional

Deprecation.

deprecateAt: string
Object
tagsRequired

Tags.

[string]: string
Map

Observed values

Outputs

Praxis records these values after observation. A dependent resource can read one with ${resources.<name>.outputs.<field>}.

imageIdString
nameString
stateString
architectureString
virtualizationTypeString
rootDeviceNameString
ownerIdString
creationDateString

Read without ownership

Data-source lookup

A data block reads an existing AMI and exposes its outputs without storing lifecycle state. The generic filter surface accepts id, name, and tag; supported combinations depend on the AWS identity used by this resource.

CUE data source
data: existing: {
  kind: "AMI"
  region: "us-west-2"
  filter: {
    name: "replace-with-provider-name"
  }
}

Understand data sources and filters →

Adopt existing infrastructure

Import

Import persists Praxis state for an existing AWS resource. For this kind, supply: Provider identifier for the existing AMI. The example starts in observed mode so Praxis reports drift without correcting it.

CLI
praxis import AMI \
  --id <provider-identifier> \
  --region us-west-2 \
  --account production \
  --observe

Choose managed or observed ownership →

Canonical contract

Complete CUE schema

The field guide above is derived from this definition. The schema remains the source of truth for accepted values, defaults, validation constraints, and outputs in the current alpha revision.

Show the complete schema
schemas/aws/ec2/ami.cue
package ec2

#AMI: {
	apiVersion: "praxis.io/alpha"
	kind:       "AMI"

	metadata: {
		name: string & =~"^[a-zA-Z0-9][a-zA-Z0-9._()/-]{0,127}$"
		labels: [string]: string
	}

	spec: {
		region:       string
		description?: string
		source: {
			fromSnapshot?: {
				snapshotId:         string
				architecture:       "x86_64" | "arm64" | *"x86_64"
				virtualizationType: "hvm" | *"hvm"
				rootDeviceName:     string | *"/dev/xvda"
				volumeType:         "gp2" | "gp3" | "io1" | "io2" | *"gp3"
				volumeSize?:        int & >0
				enaSupport?:        bool | *true
			}
			fromAMI?: {
				sourceImageId: string
				sourceRegion?: string
				encrypted?:    bool
				kmsKeyId?:     string
			}
		}
		launchPermissions?: {
			accountIds?: [...string]
			public?: bool
		}
		deprecation?: deprecateAt: string
		tags: [string]:            string
	}

	outputs?: {
		imageId:            string
		name:               string
		state:              string
		architecture:       string
		virtualizationType: string
		rootDeviceName:     string
		ownerId:            string
		creationDate:       string
	}
}

View this schema on GitHub →