Fix Terraform InvalidAMIID.Malformed Error: A Step-by-Step Guide
Encountering the InvalidAMIID.Malformed error in Terraform? This guide explains the cause and provides solutions, including manual AMI updates and dynamic.
Cloud Computing
Fix Terraform AWS OptInRequired errors. Enable services in new regions, verify account activation, check billing status
# Check if your account is fully activated
aws sts get-caller-identity
# Enable a region (if using opt-in regions)
aws account enable-region --region-name af-south-1Error: creating EC2 Instance: OptInRequired: You are not subscribed to this service.
Please go to http://aws.amazon.com to subscribe.
status code: 401Or:
Error: creating EC2 Instance: OptInRequired: In order to use this AWS Marketplace
product you need to accept terms and subscribe.New AWS accounts can take up to 24 hours to fully activate. During this time:
Error: OptInRequired: You are not subscribed to this service.Verify your account status:
These regions require explicit opt-in:
| Region | Name |
|---|---|
af-south-1 | Africa (Cape Town) |
ap-east-1 | Asia Pacific (Hong Kong) |
ap-south-2 | Asia Pacific (Hyderabad) |
ap-southeast-3 | Asia Pacific (Jakarta) |
ap-southeast-4 | Asia Pacific (Melbourne) |
eu-south-1 | Europe (Milan) |
eu-south-2 | Europe (Spain) |
eu-central-2 | Europe (Zurich) |
me-south-1 | Middle East (Bahrain) |
me-central-1 | Middle East (UAE) |
il-central-1 | Israel (Tel Aviv) |
# Enable a region
aws account enable-region --region-name af-south-1
# Check region status
aws account get-region-opt-status --region-name af-south-1Or via Console: Account → AWS Regions → Enable
Region activation takes 5-10 minutes.
If using a third-party AMI:
# The error tells you which product
Error: creating EC2 Instance: OptInRequired: In order to use this AWS Marketplace
product you need to accept terms and subscribe.terraform applyOr use an official Amazon AMI instead:
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"] # Canonical (no subscription needed)
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"]
}
}
resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
}# If in an Organization, check SCPs
aws organizations list-policies --filter SERVICE_CONTROL_POLICY
# Check account status
aws account get-contact-informationCommon SCP blocks:
{
"Effect": "Deny",
"Action": "ec2:RunInstances",
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": ["us-east-1", "eu-west-1"]
}
}
}This SCP prevents launching instances in non-approved regions.
OptInRequired usually means your AWS account is too new (wait 24h), you're using an opt-in region (enable it), or you need to subscribe to a Marketplace AMI. Check your billing status and Organization SCPs if the simpler fixes don't work.
Encountering the InvalidAMIID.Malformed error in Terraform? This guide explains the cause and provides solutions, including manual AMI updates and dynamic.
Fix Terraform AWS InvalidClientTokenId errors. Check credentials, fix expired tokens, resolve region/profile mismatches
Build a production-ready AWS VPC with Terraform. Covers subnets, route tables, NAT gateways, security groups, and network ACLs step by step.
Deploy an AWS EC2 instance with Terraform step by step. Complete guide with VPC, security groups, key pairs, user data, and production-ready configuration.