Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

feat: EC2 Terraform compat, S3 Control tags, MINISTACK_HOST, 794 tests (v1.1.14) (#55)

Nahuel Nucera6f0c5d06bdc2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aebf5d49..6f5d7b96 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,27 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
+## [1.1.14] — 2026-04-01
+
+### Added
+- **`MINISTACK_HOST` environment variable** — controls the hostname used in all response URLs (`QueueUrl`, SNS `SubscribeURL`/`UnsubscribeURL`, API Gateway `apiEndpoint`/`domainName`, CFN-provisioned SQS queues). Defaults to `localhost`. Set to your Docker Compose service name (e.g. `ministack`) so other containers can reach the returned URLs directly. Contributed by @santiagodoldan and @David2011Hernandez
+
+### Fixed
+- **EC2 `DescribeInstanceAttribute`** — added support for all standard attributes (`instanceType`, `instanceInitiatedShutdownBehavior`, `disableApiTermination`, `userData`, `rootDeviceName`, `blockDeviceMapping`, `sourceDestCheck`, `groupSet`, `ebsOptimized`, `enaSupport`, `sriovNetSupport`); required by Terraform AWS Provider >= 6.0.0 during state refresh
+- **EC2 `DescribeInstanceTypes`** — added handler returning hardware specs (vCPU, memory, network, EBS) for 12 common instance families (t2, t3, m5, c5, r5, p3); required by Terraform AWS Provider >= 6.0.0. Contributed by @samiuoi
+- **S3 Control `ListTagsForResource`** — was always returning an empty tag list; now returns tags set via `PutBucketTagging`. Fixes Terraform `aws_s3_bucket` perpetual drift when a `tags` block is configured
+
+### Changed
+- Virtual-hosted S3 and execute-api host-header matching now respects `MINISTACK_HOST`, so `{bucket}.<host>` and `{apiId}.execute-api.<host>` patterns work with any configured hostname
+
+### Tests
+- **CloudFormation e2e suite merged** — `test_cfn_e2e.py` merged into `test_services.py` and deleted; 10 e2e tests now run within the unified test session
+- **EC2 tests added** — 5 new tests covering `DescribeInstanceAttribute` and `DescribeInstanceTypes`
+- **S3 Control test added** — regression test for `ListTagsForResource` returning real bucket tags
+- 794 tests total, all passing
+
+---
+
## [1.1.13] — 2026-04-01
### Added
@@ -18,7 +39,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **README architecture diagram** — fixed box alignment and added CloudFormation to service list. Contributed by @oefrha (HackerNews)
### Tests
-- 788 tests total, all passing
+- 788 tests total (before v1.1.14 additions)
---
diff --git a/README.md b/README.md
index e3600a4e..70e03cf2 100644
--- a/README.md
+++ b/README.md
@@ -505,7 +505,7 @@ pip install boto3 pytest duckdb docker cbor2
# Start MiniStack
docker compose up -d
-# Run the full test suite (788 tests across all 34 services)
+# Run the full test suite (794 tests across all 34 services)
pytest tests/ -v
```
diff --git a/ministack/app.py b/ministack/app.py
index 8e3f9db4..97ecd23b 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -14,13 +14,20 @@ import subprocess
import uuid
from urllib.parse import parse_qs, urlparse
-# Matches host headers like "{apiId}.execute-api.localhost" or "{apiId}.execute-api.localhost:4566"
-_EXECUTE_API_RE = re.compile(r"^([a-f0-9]{8})\.execute-api\.localhost(?::\d+)?$")
+_MINISTACK_HOST = os.environ.get("MINISTACK_HOST", "localhost")
+_MINISTACK_PORT = os.environ.get("GATEWAY_PORT", "4566")
+
+# Matches host headers like "{apiId}.execute-api.<host>" or "{apiId}.execute-api.<host>:4566"
+_EXECUTE_API_RE = re.compile(
+ r"^([a-f0-9]{8})\.execute-api\." + re.escape(_MINISTACK_HOST) + r"(?::\d+)?$"
+)
# Matches virtual-hosted S3:
-# "{bucket}.localhost" or "{bucket}.localhost:4566" (boto3/SDK default)
-# "{bucket}.s3.localhost" or "{bucket}.s3.localhost:4566" (Terraform AWS provider v4+)
+# "{bucket}.<host>" or "{bucket}.<host>:4566" (boto3/SDK default)
+# "{bucket}.s3.<host>" or "{bucket}.s3.<host>:4566" (Terraform AWS provider v4+)
# Does NOT match execute-api, alb, or other sub-service hostnames.
-_S3_VHOST_RE = re.compile(r"^([^.]+)(?:\.s3)?\.localhost(?::\d+)?$")
+_S3_VHOST_RE = re.compile(
+ r"^([^.]+)(?:\.s3)?\." + re.escape(_MINISTACK_HOST) + r"(?::\d+)?$"
+)
_S3_VHOST_EXCLUDE_RE = re.compile(r"\.(execute-api|alb|emr|efs|elasticache)\.")
from ministack.core.persistence import PERSIST_STATE, load_state, save_all
@@ -215,12 +222,60 @@ async def app(scope, receive, send):
# S3 Control API — /v20180820/... with x-amz-account-id header
if path.startswith("/v20180820/"):
- if method == "GET" and path.startswith("/v20180820/tags/"):
- # ListTagsForResource — return empty tag set
- await _send_response(send, 200, {
- "Content-Type": "application/json",
- "x-amzn-requestid": request_id,
- }, json.dumps({"Tags": []}).encode())
+ if path.startswith("/v20180820/tags/"):
+ from urllib.parse import unquote
+ raw_arn = path[len("/v20180820/tags/"):]
+ arn = unquote(raw_arn)
+ # ARN format: arn:aws:s3:::bucket-name or arn:aws:s3:::bucket-name/object-key
+ bucket_name = arn.split(":::")[-1].split("/")[0] if ":::" in arn else arn.split("/")[0]
+
+ if method == "GET":
+ # ListTagsForResource — return real tags from s3._bucket_tags
+ tags = s3._bucket_tags.get(bucket_name, {})
+ tag_members = "".join(
+ f"<member><Key>{k}</Key><Value>{v}</Value></member>"
+ for k, v in tags.items()
+ )
+ xml_body = (
+ '<?xml version="1.0" encoding="UTF-8"?>'
+ '<ListTagsForResourceResult xmlns="https://awss3control.amazonaws.com/doc/2018-08-20/">'
+ f"<Tags>{tag_members}</Tags>"
+ "</ListTagsForResourceResult>"
+ ).encode()
+ await _send_response(send, 200, {
+ "Content-Type": "application/xml",
+ "x-amzn-requestid": request_id,
+ }, xml_body)
+ elif method == "PUT":
+ # TagResource — merge tags into s3._bucket_tags
+ try:
+ payload = json.loads(body) if body else {}
+ new_tags = {t["Key"]: t["Value"] for t in payload.get("Tags", [])}
+ existing = s3._bucket_tags.get(bucket_name, {})
+ existing.update(new_tags)
+ s3._bucket_tags[bucket_name] = existing
+ except Exception:
+ pass
+ await _send_response(send, 204, {
+ "x-amzn-requestid": request_id,
+ }, b"")
+ elif method == "DELETE":
+ # UntagResource — remove specified keys
+ keys_to_remove = query_params.get("tagKeys", [])
+ if isinstance(keys_to_remove, str):
+ keys_to_remove = [keys_to_remove]
+ tags = s3._bucket_tags.get(bucket_name, {})
+ for k in keys_to_remove:
+ tags.pop(k, None)
+ s3._bucket_tags[bucket_name] = tags
+ await _send_response(send, 204, {
+ "x-amzn-requestid": request_id,
+ }, b"")
+ else:
+ await _send_response(send, 200, {
+ "Content-Type": "application/json",
+ "x-amzn-requestid": request_id,
+ }, b"{}")
else:
# All other S3 Control operations — accept silently
await _send_response(send, 200, {
diff --git a/ministack/services/apigateway.py b/ministack/services/apigateway.py
index d78bdcbb..849c6e23 100644
--- a/ministack/services/apigateway.py
+++ b/ministack/services/apigateway.py
@@ -42,11 +42,15 @@ Data plane:
import json
import logging
+import os
import re
import time
from ministack.core.responses import error_response_json, new_uuid
+_HOST = os.environ.get("MINISTACK_HOST", "localhost")
+_PORT = os.environ.get("GATEWAY_PORT", "4566")
+
logger = logging.getLogger("apigateway")
ACCOUNT_ID = "000000000000"
@@ -338,7 +342,7 @@ async def _invoke_lambda_proxy(integration, api_id, stage, path, method, headers
"requestContext": {
"accountId": ACCOUNT_ID,
"apiId": api_id,
- "domainName": f"{api_id}.execute-api.localhost",
+ "domainName": f"{api_id}.execute-api.{_HOST}",
"http": {
"method": method,
"path": path,
@@ -411,7 +415,7 @@ def _create_api(data):
"apiId": api_id,
"name": data.get("name", "unnamed"),
"protocolType": data.get("protocolType", "HTTP"),
- "apiEndpoint": f"http://{api_id}.execute-api.localhost:4566",
+ "apiEndpoint": f"http://{api_id}.execute-api.{_HOST}:{_PORT}",
"createdDate": int(time.time()),
"routeSelectionExpression": data.get("routeSelectionExpression", "$request.method $request.path"),
"tags": data.get("tags", {}),
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 1cceb08a..66b6e11c 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -98,7 +98,7 @@ def _s3_delete(physical_id, props):
def _sqs_create(logical_id, props, stack_name):
name = props.get("QueueName") or f"{stack_name}-{logical_id}-{new_uuid()[:8]}"
is_fifo = name.endswith(".fifo")
- url = f"http://localhost:4566/{ACCOUNT_ID}/{name}"
+ url = f"http://{_sqs.DEFAULT_HOST}:{_sqs.DEFAULT_PORT}/{ACCOUNT_ID}/{name}"
arn = f"arn:aws:sqs:{REGION}:{ACCOUNT_ID}:{name}"
now_ts = str(int(time.time()))
diff --git a/ministack/services/ec2.py b/ministack/services/ec2.py
index 5819885a..500de80d 100644
--- a/ministack/services/ec2.py
+++ b/ministack/services/ec2.py
@@ -2248,9 +2248,130 @@ def reset():
# Action map
# ---------------------------------------------------------------------------
+def _describe_instance_attribute(p):
+ instance_id = _p(p, "InstanceId")
+ attribute = _p(p, "Attribute")
+ inst = _instances.get(instance_id)
+ if not inst:
+ return _error("InvalidInstanceID.NotFound",
+ f"The instance ID '{instance_id}' does not exist", 400)
+
+ if attribute == "instanceInitiatedShutdownBehavior":
+ value_xml = "<instanceInitiatedShutdownBehavior><value>stop</value></instanceInitiatedShutdownBehavior>"
+ elif attribute == "disableApiTermination":
+ value_xml = "<disableApiTermination><value>false</value></disableApiTermination>"
+ elif attribute == "instanceType":
+ value_xml = f"<instanceType><value>{inst.get('InstanceType', 't2.micro')}</value></instanceType>"
+ elif attribute == "userData":
+ value_xml = "<userData/>"
+ elif attribute == "rootDeviceName":
+ value_xml = f"<rootDeviceName><value>{inst.get('RootDeviceName', '/dev/xvda')}</value></rootDeviceName>"
+ elif attribute == "blockDeviceMapping":
+ value_xml = "<blockDeviceMapping/>"
+ elif attribute == "sourceDestCheck":
+ value_xml = "<sourceDestCheck><value>true</value></sourceDestCheck>"
+ elif attribute == "groupSet":
+ sgs = "".join(
+ f"<item><groupId>{sg['GroupId']}</groupId><groupName>{sg['GroupName']}</groupName></item>"
+ for sg in inst.get("SecurityGroups", [])
+ )
+ value_xml = f"<groupSet>{sgs}</groupSet>"
+ elif attribute == "ebsOptimized":
+ value_xml = "<ebsOptimized><value>false</value></ebsOptimized>"
+ elif attribute == "enaSupport":
+ value_xml = "<enaSupport><value>true</value></enaSupport>"
+ elif attribute == "sriovNetSupport":
+ value_xml = "<sriovNetSupport><value>simple</value></sriovNetSupport>"
+ else:
+ value_xml = f"<{attribute}/>"
+
+ return _xml(200, "DescribeInstanceAttributeResponse",
+ f"<instanceId>{instance_id}</instanceId>{value_xml}")
+
+
+def _describe_instance_types(p):
+ # Collect requested types
+ requested = _parse_member_list(p, "InstanceType")
+ # Common types Terraform provider v6+ queries
+ all_types = requested or [
+ "t2.micro", "t2.small", "t2.medium", "t2.large",
+ "t3.micro", "t3.small", "t3.medium", "t3.large",
+ "m5.large", "m5.xlarge", "c5.large", "c5.xlarge",
+ ]
+ items = ""
+ for itype in all_types:
+ family = itype.split(".")[0]
+ vcpus = 2 if "micro" in itype else 4 if "small" in itype else 8
+ mem_mib = 1024 if "micro" in itype else 2048 if "small" in itype else 4096
+ items += f"""<item>
+ <instanceType>{itype}</instanceType>
+ <currentGeneration>true</currentGeneration>
+ <freeTierEligible>{'true' if itype == 't2.micro' else 'false'}</freeTierEligible>
+ <supportedUsageClasses><item>on-demand</item><item>spot</item></supportedUsageClasses>
+ <supportedRootDeviceTypes><item>ebs</item></supportedRootDeviceTypes>
+ <supportedVirtualizationTypes><item>hvm</item></supportedVirtualizationTypes>
+ <bareMetal>false</bareMetal>
+ <hypervisor>xen</hypervisor>
+ <processorInfo>
+ <supportedArchitectures><item>x86_64</item></supportedArchitectures>
+ <sustainedClockSpeedInGhz>2.5</sustainedClockSpeedInGhz>
+ </processorInfo>
+ <vCpuInfo>
+ <defaultVCpus>{vcpus}</defaultVCpus>
+ <defaultCores>{vcpus}</defaultCores>
+ <defaultThreadsPerCore>1</defaultThreadsPerCore>
+ </vCpuInfo>
+ <memoryInfo><sizeInMiB>{mem_mib}</sizeInMiB></memoryInfo>
+ <instanceStorageSupported>false</instanceStorageSupported>
+ <ebsInfo>
+ <ebsOptimizedSupport>unsupported</ebsOptimizedSupport>
+ <encryptionSupport>supported</encryptionSupport>
+ <ebsOptimizedInfo>
+ <baselineBandwidthInMbps>256</baselineBandwidthInMbps>
+ <baselineThroughputInMBps>32.0</baselineThroughputInMBps>
+ <baselineIops>2000</baselineIops>
+ <maximumBandwidthInMbps>256</maximumBandwidthInMbps>
+ <maximumThroughputInMBps>32.0</maximumThroughputInMBps>
+ <maximumIops>2000</maximumIops>
+ </ebsOptimizedInfo>
+ <nvmeSupport>unsupported</nvmeSupport>
+ </ebsInfo>
+ <networkInfo>
+ <networkPerformance>Low to Moderate</networkPerformance>
+ <maximumNetworkInterfaces>2</maximumNetworkInterfaces>
+ <maximumNetworkCards>1</maximumNetworkCards>
+ <defaultNetworkCardIndex>0</defaultNetworkCardIndex>
+ <networkCards><item>
+ <networkCardIndex>0</networkCardIndex>
+ <networkPerformance>Low to Moderate</networkPerformance>
+ <maximumNetworkInterfaces>2</maximumNetworkInterfaces>
+ <baselineBandwidthInGbps>0.1</baselineBandwidthInGbps>
+ <peakBandwidthInGbps>0.5</peakBandwidthInGbps>
+ </item></networkCards>
+ <ipv4AddressesPerInterface>2</ipv4AddressesPerInterface>
+ <ipv6AddressesPerInterface>2</ipv6AddressesPerInterface>
+ <ipv6Supported>true</ipv6Supported>
+ <enaSupport>required</enaSupport>
+ <efaSupported>false</efaSupported>
+ </networkInfo>
+ <placementGroupInfo>
+ <supportedStrategies><item>partition</item><item>spread</item></supportedStrategies>
+ </placementGroupInfo>
+ <hibernationSupported>false</hibernationSupported>
+ <burstablePerformanceSupported>{'true' if family in ('t2','t3','t4g') else 'false'}</burstablePerformanceSupported>
+ <dedicatedHostsSupported>false</dedicatedHostsSupported>
+ <autoRecoverySupported>true</autoRecoverySupported>
+ </item>"""
+
+ return _xml(200, "DescribeInstanceTypesResponse",
+ f"<instanceTypeSet>{items}</instanceTypeSet>")
+
+
_ACTION_MAP = {
"RunInstances": _run_instances,
"DescribeInstances": _describe_instances,
+ "DescribeInstanceAttribute": _describe_instance_attribute,
+ "DescribeInstanceTypes": _describe_instance_types,
"TerminateInstances": _terminate_instances,
"StopInstances": _stop_instances,
"StartInstances": _start_instances,
diff --git a/ministack/services/sns.py b/ministack/services/sns.py
index 98ebb012..399c64ea 100644
--- a/ministack/services/sns.py
+++ b/ministack/services/sns.py
@@ -14,9 +14,13 @@ import asyncio
import hashlib
import json
import logging
+import os
import time
from urllib.parse import parse_qs
+_HOST = os.environ.get("MINISTACK_HOST", "localhost")
+_PORT = os.environ.get("GATEWAY_PORT", "4566")
+
import ministack.services.lambda_svc as _lambda_svc
from ministack.core.responses import new_uuid
from ministack.services import sqs as _sqs
@@ -572,7 +576,7 @@ async def _send_subscription_confirmation(topic_arn: str, sub: dict):
"Token": token,
"Message": f"You have chosen to subscribe to the topic {topic_arn}. "
f"To confirm the subscription, visit the SubscribeURL included in this message.",
- "SubscribeURL": f"http://localhost:4566/?Action=ConfirmSubscription&TopicArn={topic_arn}&Token={token}",
+ "SubscribeURL": f"http://{_HOST}:{_PORT}/?Action=ConfirmSubscription&TopicArn={topic_arn}&Token={token}",
"Timestamp": time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime()),
"SignatureVersion": "1",
"Signature": "FAKE",
@@ -923,7 +927,7 @@ def _build_envelope(topic_arn: str, msg_id: str, message: str, subject: str,
"SignatureVersion": "1",
"Signature": "FAKE",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-fake.pem",
- "UnsubscribeURL": f"http://localhost:4566/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:{REGION}:{ACCOUNT_ID}:example",
+ "UnsubscribeURL": f"http://{_HOST}:{_PORT}/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:{REGION}:{ACCOUNT_ID}:example",
}
if message_attributes:
diff --git a/pyproject.toml b/pyproject.toml
index 5b32393e..5f0eafda 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ministack"
-version = "1.1.13"
+version = "1.1.14"
description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"
readme = "README.md"
license = { file = "LICENSE" }
diff --git a/tests/test_cfn_e2e.py b/tests/test_cfn_e2e.py
deleted file mode 100644
index 5e456492..00000000
--- a/tests/test_cfn_e2e.py
+++ /dev/null
@@ -1,292 +0,0 @@
-"""
-End-to-end test: deploy a CloudFormation stack and use every resource it creates.
-
-Verifies that CFN-provisioned resources are fully functional — not just metadata
-stubs but real working S3 buckets, SQS queues, SNS topics, Lambda functions, etc.
-
-Requires a running ministack server on MINISTACK_ENDPOINT (default localhost:4566).
-"""
-
-import json
-import os
-import time
-
-import boto3
-import pytest
-from botocore.config import Config
-from botocore.exceptions import ClientError
-
-ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
-STACK_NAME = "e2e-test"
-
-_kwargs = dict(
- endpoint_url=ENDPOINT,
- aws_access_key_id="test",
- aws_secret_access_key="test",
- region_name="us-east-1",
- config=Config(region_name="us-east-1", retries={"max_attempts": 0}),
-)
-
-
-def _client(service):
- return boto3.client(service, **_kwargs)
-
-
-def _wait_stack(cfn, name, timeout=15):
- deadline = time.time() + timeout
- while time.time() < deadline:
- stacks = cfn.describe_stacks(StackName=name)["Stacks"]
- status = stacks[0]["StackStatus"]
- if not status.endswith("_IN_PROGRESS"):
- return stacks[0]
- time.sleep(0.5)
- raise TimeoutError(f"Stack {name} stuck at {status}")
-
-
-TEMPLATE = """
-AWSTemplateFormatVersion: '2010-09-09'
-Description: E2E test stack — verifies CFN resources are functional
-
-Parameters:
- Env:
- Type: String
- Default: e2etest
-
-Resources:
- Bucket:
- Type: AWS::S3::Bucket
- Properties:
- BucketName: !Sub "${AWS::StackName}-${Env}-assets"
-
- Queue:
- Type: AWS::SQS::Queue
- Properties:
- QueueName: !Sub "${AWS::StackName}-${Env}-events"
- VisibilityTimeout: 120
-
- Topic:
- Type: AWS::SNS::Topic
- Properties:
- TopicName: !Sub "${AWS::StackName}-${Env}-alerts"
-
- Role:
- Type: AWS::IAM::Role
- Properties:
- RoleName: !Sub "${AWS::StackName}-${Env}-role"
- AssumeRolePolicyDocument:
- Version: '2012-10-17'
- Statement:
- - Effect: Allow
- Principal:
- Service: lambda.amazonaws.com
- Action: sts:AssumeRole
-
- Processor:
- Type: AWS::Lambda::Function
- Properties:
- FunctionName: !Sub "${AWS::StackName}-${Env}-processor"
- Runtime: python3.12
- Handler: index.handler
- Role: !GetAtt Role.Arn
- Code:
- ZipFile: |
- def handler(event, context):
- return {"statusCode": 200}
-
- QueueUrlParam:
- Type: AWS::SSM::Parameter
- Properties:
- Name: !Sub "/${AWS::StackName}/${Env}/queue-url"
- Type: String
- Value: !Ref Queue
-
-Outputs:
- BucketName:
- Value: !Ref Bucket
- Export:
- Name: !Sub "${AWS::StackName}-bucket"
- QueueUrl:
- Value: !Ref Queue
- TopicArn:
- Value: !Ref Topic
- ProcessorArn:
- Value: !GetAtt Processor.Arn
- RoleArn:
- Value: !GetAtt Role.Arn
-"""
-
-
[email protected](scope="module")
-def stack():
- """Deploy the stack once for all tests in this module."""
- cfn = _client("cloudformation")
-
- # Clean up from previous run
- try:
- cfn.delete_stack(StackName=STACK_NAME)
- _wait_stack(cfn, STACK_NAME)
- except ClientError:
- pass
-
- cfn.create_stack(StackName=STACK_NAME, TemplateBody=TEMPLATE)
- s = _wait_stack(cfn, STACK_NAME)
- assert s["StackStatus"] == "CREATE_COMPLETE", f"Stack failed: {s.get('StackStatusReason')}"
-
- outputs = {o["OutputKey"]: o["OutputValue"] for o in s.get("Outputs", [])}
- yield outputs
-
- cfn.delete_stack(StackName=STACK_NAME)
- _wait_stack(cfn, STACK_NAME)
-
-
-# ── S3 ──
-
-def test_s3_put_and_get(stack):
- s3 = _client("s3")
- bucket = stack["BucketName"]
- body = json.dumps({"id": "001", "total": 99.99})
-
- s3.put_object(Bucket=bucket, Key="orders/order-001.json", Body=body.encode())
- obj = s3.get_object(Bucket=bucket, Key="orders/order-001.json")
- data = json.loads(obj["Body"].read())
-
- assert data["id"] == "001"
- assert data["total"] == 99.99
-
-
-def test_s3_list_objects(stack):
- s3 = _client("s3")
- bucket = stack["BucketName"]
-
- s3.put_object(Bucket=bucket, Key="docs/readme.txt", Body=b"hello")
- listing = s3.list_objects_v2(Bucket=bucket)
-
- assert listing["KeyCount"] >= 1
- keys = [o["Key"] for o in listing["Contents"]]
- assert "docs/readme.txt" in keys
-
-
-# ── SQS ──
-
-def test_sqs_send_receive_delete(stack):
- sqs = _client("sqs")
- url = stack["QueueUrl"]
-
- sqs.send_message(QueueUrl=url, MessageBody=json.dumps({"event": "order.created"}))
- sqs.send_message(QueueUrl=url, MessageBody=json.dumps({"event": "order.shipped"}))
-
- msgs = sqs.receive_message(QueueUrl=url, MaxNumberOfMessages=10, WaitTimeSeconds=1)
- received = msgs.get("Messages", [])
- assert len(received) == 2
-
- events = sorted(json.loads(m["Body"])["event"] for m in received)
- assert events == ["order.created", "order.shipped"]
-
- for m in received:
- sqs.delete_message(QueueUrl=url, ReceiptHandle=m["ReceiptHandle"])
-
- empty = sqs.receive_message(QueueUrl=url, MaxNumberOfMessages=10, WaitTimeSeconds=1)
- assert len(empty.get("Messages", [])) == 0
-
-
-# ── SNS ──
-
-def test_sns_publish(stack):
- sns = _client("sns")
- topic_arn = stack["TopicArn"]
-
- resp = sns.publish(TopicArn=topic_arn, Subject="Test Alert",
- Message=json.dumps({"alert": "test", "severity": "low"}))
- assert "MessageId" in resp
-
-
-# ── SSM ──
-
-def test_ssm_read_cfn_param(stack):
- ssm = _client("ssm")
- param = ssm.get_parameter(Name=f"/{STACK_NAME}/e2etest/queue-url")["Parameter"]
-
- assert param["Value"] == stack["QueueUrl"]
-
-
-def test_ssm_write_and_read(stack):
- ssm = _client("ssm")
- ssm.put_parameter(Name=f"/{STACK_NAME}/e2etest/flags", Type="String",
- Value=json.dumps({"dark_mode": True}))
-
- flags = json.loads(ssm.get_parameter(Name=f"/{STACK_NAME}/e2etest/flags")["Parameter"]["Value"])
- assert flags["dark_mode"] is True
-
-
-# ── Lambda ──
-
-def test_lambda_invoke(stack):
- lam = _client("lambda")
- resp = lam.invoke(FunctionName=f"{STACK_NAME}-e2etest-processor",
- Payload=json.dumps({"action": "test"}).encode())
- assert resp["StatusCode"] == 200
-
-
-# ── IAM wiring ──
-
-def test_lambda_role_matches_iam_role(stack):
- lam = _client("lambda")
- iam = _client("iam")
-
- fn = lam.get_function(FunctionName=f"{STACK_NAME}-e2etest-processor")["Configuration"]
- role = iam.get_role(RoleName=f"{STACK_NAME}-e2etest-role")["Role"]
-
- assert fn["Role"] == role["Arn"]
-
-
-# ── Cross-service pipeline ──
-
-def test_e2e_pipeline(stack):
- """S3 upload → SQS queue → read back from S3 → SNS alert."""
- s3 = _client("s3")
- sqs = _client("sqs")
- sns = _client("sns")
- bucket = stack["BucketName"]
- url = stack["QueueUrl"]
- topic_arn = stack["TopicArn"]
-
- # Upload orders to S3
- for i in range(3):
- order = {"id": f"pipe-{i}", "item": f"widget-{i}", "qty": (i + 1) * 5}
- s3.put_object(Bucket=bucket, Key=f"pipeline/order-{i}.json",
- Body=json.dumps(order).encode())
-
- # Queue processing events
- for i in range(3):
- sqs.send_message(QueueUrl=url,
- MessageBody=json.dumps({"event": "process", "key": f"pipeline/order-{i}.json"}))
-
- # Consume queue, read each order from S3
- msgs = sqs.receive_message(QueueUrl=url, MaxNumberOfMessages=10, WaitTimeSeconds=1)
- assert len(msgs.get("Messages", [])) == 3
-
- total_qty = 0
- for m in msgs["Messages"]:
- body = json.loads(m["Body"])
- obj = s3.get_object(Bucket=bucket, Key=body["key"])
- order = json.loads(obj["Body"].read())
- total_qty += order["qty"]
- sqs.delete_message(QueueUrl=url, ReceiptHandle=m["ReceiptHandle"])
-
- assert total_qty == 5 + 10 + 15 # 30
-
- # Send completion alert
- resp = sns.publish(TopicArn=topic_arn, Subject="Pipeline Done",
- Message=json.dumps({"processed": 3, "total_qty": total_qty}))
- assert "MessageId" in resp
-
-
-# ── Exports ──
-
-def test_cfn_exports_available(stack):
- cfn = _client("cloudformation")
- exports = cfn.list_exports()["Exports"]
- names = {e["Name"]: e["Value"] for e in exports}
-
- assert f"{STACK_NAME}-bucket" in names
- assert names[f"{STACK_NAME}-bucket"] == stack["BucketName"]
diff --git a/tests/test_services.py b/tests/test_services.py
index 5fc6a6aa..89682662 100644
--- a/tests/test_services.py
+++ b/tests/test_services.py
@@ -328,6 +328,29 @@ def test_s3_bucket_tagging(s3):
assert exc.value.response["Error"]["Code"] == "NoSuchTagSet"
+def test_s3_control_list_tags_for_resource(s3):
+ """S3 Control ListTagsForResource must return tags set via PutBucketTagging.
+
+ Regression: Terraform AWS Provider >= 5 calls s3control:ListTagsForResource
+ when a `tags` block is set on aws_s3_bucket. The handler was returning an
+ empty list regardless of bucket tags, causing perpetual drift.
+ """
+ from conftest import make_client
+ bkt = "intg-s3control-tags"
+ account_id = "123456789012"
+ s3.create_bucket(Bucket=bkt)
+ s3.put_bucket_tagging(
+ Bucket=bkt,
+ Tagging={"TagSet": [{"Key": "name", "Value": "ministack-test"}]},
+ )
+
+ s3control = make_client("s3control")
+ arn = f"arn:aws:s3:::{bkt}"
+ resp = s3control.list_tags_for_resource(AccountId=account_id, ResourceArn=arn)
+ tags = {t["Key"]: t["Value"] for t in resp.get("Tags", [])}
+ assert tags.get("name") == "ministack-test"
+
+
def test_s3_bucket_policy(s3):
bkt = "intg-s3-policy"
s3.create_bucket(Bucket=bkt)
@@ -15671,3 +15694,257 @@ def test_cfn_update_rollback_on_failure(cfn, s3):
assert stack["StackStatus"] == "UPDATE_ROLLBACK_COMPLETE"
s3.head_bucket(Bucket="cfn-t18-orig")
+
+
+# ========== EC2 — DescribeInstanceAttribute / DescribeInstanceTypes ==========
+
+
+def test_ec2_describe_instance_attribute_instance_type(ec2):
+ resp = ec2.run_instances(ImageId="ami-00000000", MinCount=1, MaxCount=1, InstanceType="t3.micro")
+ iid = resp["Instances"][0]["InstanceId"]
+
+ attr = ec2.describe_instance_attribute(InstanceId=iid, Attribute="instanceType")
+ assert attr["InstanceId"] == iid
+ assert attr["InstanceType"]["Value"] == "t3.micro"
+
+ ec2.terminate_instances(InstanceIds=[iid])
+
+
+def test_ec2_describe_instance_attribute_shutdown_behavior(ec2):
+ resp = ec2.run_instances(ImageId="ami-00000000", MinCount=1, MaxCount=1)
+ iid = resp["Instances"][0]["InstanceId"]
+
+ attr = ec2.describe_instance_attribute(InstanceId=iid, Attribute="instanceInitiatedShutdownBehavior")
+ assert attr["InstanceId"] == iid
+ assert attr["InstanceInitiatedShutdownBehavior"]["Value"] == "stop"
+
+ ec2.terminate_instances(InstanceIds=[iid])
+
+
+def test_ec2_describe_instance_attribute_not_found(ec2):
+ from botocore.exceptions import ClientError
+ with pytest.raises(ClientError) as exc:
+ ec2.describe_instance_attribute(InstanceId="i-000000000000nonex", Attribute="instanceType")
+ assert exc.value.response["Error"]["Code"] == "InvalidInstanceID.NotFound"
+
+
+def test_ec2_describe_instance_types_defaults(ec2):
+ resp = ec2.describe_instance_types()
+ types = [t["InstanceType"] for t in resp["InstanceTypes"]]
+ assert "t2.micro" in types
+ assert "t3.micro" in types
+ assert len(resp["InstanceTypes"]) >= 4
+ # Spot-check shape
+ sample = resp["InstanceTypes"][0]
+ assert "VCpuInfo" in sample
+ assert "MemoryInfo" in sample
+ assert sample["VCpuInfo"]["DefaultVCpus"] >= 1
+ assert sample["MemoryInfo"]["SizeInMiB"] >= 512
+
+
+def test_ec2_describe_instance_types_filter(ec2):
+ resp = ec2.describe_instance_types(InstanceTypes=["t2.micro", "m5.large"])
+ types = {t["InstanceType"] for t in resp["InstanceTypes"]}
+ assert types == {"t2.micro", "m5.large"}
+
+
+# ========== CloudFormation — End-to-End ==========
+
+_E2E_STACK = "e2e-test"
+_E2E_TEMPLATE = """
+AWSTemplateFormatVersion: '2010-09-09'
+Description: E2E test stack — verifies CFN resources are functional
+
+Parameters:
+ Env:
+ Type: String
+ Default: e2etest
+
+Resources:
+ Bucket:
+ Type: AWS::S3::Bucket
+ Properties:
+ BucketName: !Sub "${AWS::StackName}-${Env}-assets"
+
+ Queue:
+ Type: AWS::SQS::Queue
+ Properties:
+ QueueName: !Sub "${AWS::StackName}-${Env}-events"
+ VisibilityTimeout: 120
+
+ Topic:
+ Type: AWS::SNS::Topic
+ Properties:
+ TopicName: !Sub "${AWS::StackName}-${Env}-alerts"
+
+ Role:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: !Sub "${AWS::StackName}-${Env}-role"
+ AssumeRolePolicyDocument:
+ Version: '2012-10-17'
+ Statement:
+ - Effect: Allow
+ Principal:
+ Service: lambda.amazonaws.com
+ Action: sts:AssumeRole
+
+ Processor:
+ Type: AWS::Lambda::Function
+ Properties:
+ FunctionName: !Sub "${AWS::StackName}-${Env}-processor"
+ Runtime: python3.12
+ Handler: index.handler
+ Role: !GetAtt Role.Arn
+ Code:
+ ZipFile: |
+ def handler(event, context):
+ return {"statusCode": 200}
+
+ QueueUrlParam:
+ Type: AWS::SSM::Parameter
+ Properties:
+ Name: !Sub "/${AWS::StackName}/${Env}/queue-url"
+ Type: String
+ Value: !Ref Queue
+
+Outputs:
+ BucketName:
+ Value: !Ref Bucket
+ Export:
+ Name: !Sub "${AWS::StackName}-bucket"
+ QueueUrl:
+ Value: !Ref Queue
+ TopicArn:
+ Value: !Ref Topic
+ ProcessorArn:
+ Value: !GetAtt Processor.Arn
+ RoleArn:
+ Value: !GetAtt Role.Arn
+"""
+
+
[email protected](scope="module")
+def cfn_e2e_stack(cfn):
+ """Deploy the e2e stack once for all e2e tests in this module."""
+ # Clean up from a previous run
+ try:
+ cfn.delete_stack(StackName=_E2E_STACK)
+ _wait_stack(cfn, _E2E_STACK)
+ except Exception:
+ pass
+
+ cfn.create_stack(StackName=_E2E_STACK, TemplateBody=_E2E_TEMPLATE)
+ s = _wait_stack(cfn, _E2E_STACK)
+ assert s["StackStatus"] == "CREATE_COMPLETE", f"Stack failed: {s.get('StackStatusReason')}"
+
+ outputs = {o["OutputKey"]: o["OutputValue"] for o in s.get("Outputs", [])}
+ yield outputs
+
+ cfn.delete_stack(StackName=_E2E_STACK)
+ _wait_stack(cfn, _E2E_STACK)
+
+
+def test_cfn_e2e_s3_put_and_get(cfn_e2e_stack, s3):
+ bucket = cfn_e2e_stack["BucketName"]
+ body = json.dumps({"id": "001", "total": 99.99})
+ s3.put_object(Bucket=bucket, Key="orders/order-001.json", Body=body.encode())
+ obj = s3.get_object(Bucket=bucket, Key="orders/order-001.json")
+ data = json.loads(obj["Body"].read())
+ assert data["id"] == "001"
+ assert data["total"] == 99.99
+
+
+def test_cfn_e2e_s3_list_objects(cfn_e2e_stack, s3):
+ bucket = cfn_e2e_stack["BucketName"]
+ s3.put_object(Bucket=bucket, Key="docs/readme.txt", Body=b"hello")
+ listing = s3.list_objects_v2(Bucket=bucket)
+ assert listing["KeyCount"] >= 1
+ keys = [o["Key"] for o in listing["Contents"]]
+ assert "docs/readme.txt" in keys
+
+
+def test_cfn_e2e_sqs_send_receive_delete(cfn_e2e_stack, sqs):
+ url = cfn_e2e_stack["QueueUrl"]
+ sqs.send_message(QueueUrl=url, MessageBody=json.dumps({"event": "order.created"}))
+ sqs.send_message(QueueUrl=url, MessageBody=json.dumps({"event": "order.shipped"}))
+ msgs = sqs.receive_message(QueueUrl=url, MaxNumberOfMessages=10, WaitTimeSeconds=1)
+ received = msgs.get("Messages", [])
+ assert len(received) == 2
+ events = sorted(json.loads(m["Body"])["event"] for m in received)
+ assert events == ["order.created", "order.shipped"]
+ for m in received:
+ sqs.delete_message(QueueUrl=url, ReceiptHandle=m["ReceiptHandle"])
+ empty = sqs.receive_message(QueueUrl=url, MaxNumberOfMessages=10, WaitTimeSeconds=1)
+ assert len(empty.get("Messages", [])) == 0
+
+
+def test_cfn_e2e_sns_publish(cfn_e2e_stack, sns):
+ topic_arn = cfn_e2e_stack["TopicArn"]
+ resp = sns.publish(TopicArn=topic_arn, Subject="Test Alert",
+ Message=json.dumps({"alert": "test", "severity": "low"}))
+ assert "MessageId" in resp
+
+
+def test_cfn_e2e_ssm_read_cfn_param(cfn_e2e_stack, ssm):
+ param = ssm.get_parameter(Name=f"/{_E2E_STACK}/e2etest/queue-url")["Parameter"]
+ assert param["Value"] == cfn_e2e_stack["QueueUrl"]
+
+
+def test_cfn_e2e_ssm_write_and_read(cfn_e2e_stack, ssm):
+ ssm.put_parameter(Name=f"/{_E2E_STACK}/e2etest/flags", Type="String",
+ Value=json.dumps({"dark_mode": True}))
+ flags = json.loads(ssm.get_parameter(Name=f"/{_E2E_STACK}/e2etest/flags")["Parameter"]["Value"])
+ assert flags["dark_mode"] is True
+
+
+def test_cfn_e2e_lambda_invoke(cfn_e2e_stack, lam):
+ resp = lam.invoke(FunctionName=f"{_E2E_STACK}-e2etest-processor",
+ Payload=json.dumps({"action": "test"}).encode())
+ assert resp["StatusCode"] == 200
+
+
+def test_cfn_e2e_lambda_role_matches_iam_role(cfn_e2e_stack, lam, iam):
+ fn = lam.get_function(FunctionName=f"{_E2E_STACK}-e2etest-processor")["Configuration"]
+ role = iam.get_role(RoleName=f"{_E2E_STACK}-e2etest-role")["Role"]
+ assert fn["Role"] == role["Arn"]
+
+
+def test_cfn_e2e_pipeline(cfn_e2e_stack, s3, sqs, sns):
+ """S3 upload → SQS queue → read back from S3 → SNS alert."""
+ bucket = cfn_e2e_stack["BucketName"]
+ url = cfn_e2e_stack["QueueUrl"]
+ topic_arn = cfn_e2e_stack["TopicArn"]
+
+ for i in range(3):
+ order = {"id": f"pipe-{i}", "item": f"widget-{i}", "qty": (i + 1) * 5}
+ s3.put_object(Bucket=bucket, Key=f"pipeline/order-{i}.json",
+ Body=json.dumps(order).encode())
+
+ for i in range(3):
+ sqs.send_message(QueueUrl=url,
+ MessageBody=json.dumps({"event": "process", "key": f"pipeline/order-{i}.json"}))
+
+ msgs = sqs.receive_message(QueueUrl=url, MaxNumberOfMessages=10, WaitTimeSeconds=1)
+ assert len(msgs.get("Messages", [])) == 3
+
+ total_qty = 0
+ for m in msgs["Messages"]:
+ body = json.loads(m["Body"])
+ obj = s3.get_object(Bucket=bucket, Key=body["key"])
+ order = json.loads(obj["Body"].read())
+ total_qty += order["qty"]
+ sqs.delete_message(QueueUrl=url, ReceiptHandle=m["ReceiptHandle"])
+
+ assert total_qty == 5 + 10 + 15
+
+ resp = sns.publish(TopicArn=topic_arn, Subject="Pipeline Done",
+ Message=json.dumps({"processed": 3, "total_qty": total_qty}))
+ assert "MessageId" in resp
+
+
+def test_cfn_e2e_exports_available(cfn_e2e_stack, cfn):
+ exports = cfn.list_exports()["Exports"]
+ names = {e["Name"]: e["Value"] for e in exports}
+ assert f"{_E2E_STACK}-bucket" in names
+ assert names[f"{_E2E_STACK}-bucket"] == cfn_e2e_stack["BucketName"]