
Receiving AWS IoT Core HTTP Rule Actions with an API Gateway That Only Allows a Dedicated IPv6 Range
This page has been translated by machine translation. View original
Introduction
On November 25, 2026, the source IPv6 ranges used when the AWS IoT Core HTTP rule action sends to an arbitrary HTTPS endpoint were published.
In this article, I set up an API Gateway endpoint that publishes only an AAAA record, to stand in for the destination of an HTTP rule action. I attach a resource policy that allows the IPv6 ranges published for the IoT Core HTTP rule action, and then check the results of delivery and denial.
Test Environment
- Region: Tokyo (ap-northeast-1)
- AWS CLI: 2.42.4
- Endpoint: API Gateway REST API (Regional, dualstack)
- Stage: v1
- Resource policy: none (when the API is newly created)
- DNS: Route 53 alias records (A and AAAA)
- Hostname: iot-v6.example.com
- Certificate: ACM public certificate (wildcard)
Preparing the Endpoint
Lambda and API Gateway
I place a Lambda function that outputs the source address of received requests to CloudWatch Logs behind a REST API with proxy integration. For the source address, I use the value recognized by API Gateway (requestContext.identity.sourceIp).
I created the REST API with dualstack specified.
aws apigateway create-rest-api --name <API 名> --endpoint-configuration types=REGIONAL,ipAddressType=dualstack
I created an ANY method (Lambda proxy integration) on the {proxy+} resource and on the root / where the destination confirmation request (described later) arrives, and deployed to stage v1.
Lambda code (index.py) and script to view logs (show-ingest-logs.sh)
index.py outputs the received content and the source IP to the logs.
import json
def handler(event, context):
# Output the received content and the source IP that API Gateway saw to the logs
headers = event.get("headers") or {}
print(json.dumps({
"sourceIp": event["requestContext"]["identity"]["sourceIp"],
"path": event.get("path"),
"messageType": headers.get("x-amz-rules-engine-message-type"),
"body": event.get("body"),
}))
return {"statusCode": 200, "body": "ok"}
show-ingest-logs.sh outputs the source and body of requests that arrived at /ingest in chronological order.
#!/usr/bin/env bash
# Display requests that arrived at /ingest, in chronological order, with sourceIp and body
aws logs filter-log-events --log-group-name /aws/lambda/<関数名> --output json \
| jq -r '.events[] | select(.message|startswith("{")) | (.message|fromjson) | select(.path=="/ingest") | [.sourceIp, .body] | @tsv'
Custom Domain and DNS
The IoT Core rules engine connects over IPv6 only when the hostname has only an AAAA record. So, until the destination is confirmed, I place both A and AAAA and proceed over IPv4, and I test the restriction by the IPv6 range in a state where A is deleted and only AAAA remains.
I used a wildcard certificate issued by ACM, created the custom domain also as dualstack, and attached a base path mapping to stage v1.
aws apigateway create-domain-name --domain-name iot-v6.example.com --regional-certificate-arn <ACM 証明書の ARN> --endpoint-configuration types=REGIONAL,ipAddressType=dualstack --security-policy TLS_1_2
aws apigateway create-base-path-mapping --domain-name iot-v6.example.com --rest-api-id <REST API の ID> --stage v1
In Route 53, I created A and AAAA alias records pointing to the API Gateway custom domain. For DNSName, specify the regionalDomainName output by create-domain-name. For HostedZoneId, specify regionalHostedZoneId.
Route 53 records (r53-create-a-aaaa.json)
{"Changes":[
{"Action":"CREATE","ResourceRecordSet":{"Name":"iot-v6.example.com","Type":"A","AliasTarget":{"HostedZoneId":"Z1YSHQZHG15GKL","DNSName":"d-xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com","EvaluateTargetHealth":false}}},
{"Action":"CREATE","ResourceRecordSet":{"Name":"iot-v6.example.com","Type":"AAAA","AliasTarget":{"HostedZoneId":"Z1YSHQZHG15GKL","DNSName":"d-xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com","EvaluateTargetHealth":false}}}
]}
aws route53 change-resource-record-sets --hosted-zone-id <ホストゾーンの ID> --change-batch file://r53-create-a-aaaa.json
Creating the Destination and Rule
Confirming and Enabling the Destination
When you create an HTTP rule action destination, a confirmation request arrives at the API.
aws iot create-topic-rule-destination --destination-configuration httpUrlConfiguration={confirmationUrl=https://iot-v6.example.com}
With both A and AAAA present, the source of the confirmation request was IPv4. You can view the Lambda logs with the following command.
aws logs filter-log-events --log-group-name /aws/lambda/<関数名> --filter-pattern DestinationConfirmation --query "events[].message" --output text
{"sourceIp": "43.207.97.99", "path": "/", "messageType": "DestinationConfirmation", "body": "..."}
I passed the confirmationToken contained in the body to confirm-topic-rule-destination to confirm the destination, and then enabled it.
aws iot confirm-topic-rule-destination --confirmation-token <確認トークン>
aws iot update-topic-rule-destination --arn <宛先の ARN> --status ENABLED
The destination status was IN_PROGRESS immediately after creation, DISABLED after confirm, and ENABLED after update. Since confirm and update exit without outputting anything, check the status with the following command.
aws iot get-topic-rule-destination --arn <宛先の ARN> --query topicRuleDestination.status
Rule
I created a rule with an HTTP rule action. For confirmationUrl I specified the destination confirmation target (the root), and for url I specified /ingest as the delivery target.
{"sql":"SELECT * FROM 'ipv6verify/test'","awsIotSqlVersion":"2016-03-23","ruleDisabled":false,
"actions":[{"http":{"url":"https://iot-v6.example.com/ingest","confirmationUrl":"https://iot-v6.example.com"}}]}
aws iot create-topic-rule --rule-name ipv6_verify_rule --topic-rule-payload file://rule.json
Checking the Source Address
When Both A and AAAA Exist
With both A and AAAA in place, I published a message.
aws iot-data publish --topic ipv6verify/test --cli-binary-format raw-in-base64-out --payload '{"seq":1,"phase":"A+AAAA"}'
Here is the line for this message from the output of show-ingest-logs.sh. The source was IPv4.
52.194.182.218 {"seq":1,"phase":"A+AAAA"}
When Only AAAA Exists
I deleted the A record.
{"Changes":[{"Action":"DELETE","ResourceRecordSet":{"Name":"iot-v6.example.com","Type":"A","AliasTarget":{"HostedZoneId":"Z1YSHQZHG15GKL","DNSName":"d-xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com","EvaluateTargetHealth":false}}}]}
aws route53 change-resource-record-sets --hosted-zone-id <ホストゾーンの ID> --change-batch file://r53-delete-a.json
To avoid the lag before the change takes effect, I waited about a minute and then ran dig.
for T in A AAAA; do echo "# $T"; dig +short $T iot-v6.example.com @1.1.1.1; done
# A
# AAAA
2406:da14:740:5a01:79cc:769:adce:dbb7
2406:da14:740:5a03:b30b:fad8:fd3b:383b
2406:da14:740:5a02:dbae:d049:9872:1430
After confirming that A could not be resolved, I published a message.
aws iot-data publish --topic ipv6verify/test --cli-binary-format raw-in-base64-out --payload '{"seq":2,"phase":"AAAA-only"}'
The line for this message from the output of show-ingest-logs.sh is as follows.
2406:da33:4000:1:bb93:c92a:a230:622c {"seq":2,"phase":"AAAA-only"}
The source became IPv6. The dedicated IPv6 ranges for IoT Core are listed as a /48 per region in the table in the Developer Guide. Here is an excerpt of the major regions.
| Region | IPv6 address range |
|---|---|
| us-east-1 | 2600:1f33:8000::/48 |
| us-west-2 | 2600:1f33:4000::/48 |
| ap-northeast-1 | 2406:da33:4000::/48 |
| ap-northeast-2 | 2406:da33:2000::/48 |
| ap-southeast-1 | 2406:da33:8000::/48 |
| eu-central-1 | 2a05:d033:4000::/48 |
| eu-west-1 | 2a05:d033:8000::/48 |
Comparing this source with the ap-northeast-1 range, the first 3 blocks (2406:da33:4000) match.
送信元 2406:da33:4000:1:bb93:c92a:a230:622c
レンジ 2406:da33:4000::/48
Allowing the Range with a Resource Policy
Setting the Policy
While keeping only the AAAA record, I set the following resource policy on the REST API. It allows execute-api:Invoke for all principals, and then denies the request unless the source IP is within the Tokyo region (ap-northeast-1) range 2406:da33:4000::/48.
{
"Version": "2012-10-17",
"Statement": [
{"Effect": "Allow", "Principal": "*", "Action": "execute-api:Invoke", "Resource": "execute-api:/*"},
{"Effect": "Deny", "Principal": "*", "Action": "execute-api:Invoke", "Resource": "execute-api:/*",
"Condition": {"NotIpAddress": {"aws:SourceIp": "2406:da33:4000::/48"}}}
]
}
After setting the policy on the API, I redeployed the stage.
Commands to apply the policy (patch-policy.json)
patch-policy.json is the content of resource-policy.json escaped into a JSON string. That string is put into the value of an operation that replaces /policy.
[{"op": "replace", "path": "/policy", "value": "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\", \"Principal\": \"*\", \"Action\": \"execute-api:Invoke\", \"Resource\": \"execute-api:/*\"}, {\"Effect\": \"Deny\", \"Principal\": \"*\", \"Action\": \"execute-api:Invoke\", \"Resource\": \"execute-api:/*\", \"Condition\": {\"NotIpAddress\": {\"aws:SourceIp\": \"2406:da33:4000::/48\"}}}]}"}]
aws apigateway update-rest-api --rest-api-id <REST API の ID> --patch-operations file://patch-policy.json
aws apigateway create-deployment --rest-api-id <REST API の ID> --stage-name v1
Results of Delivery and Denial
With the policy applied, I published a message.
aws iot-data publish --topic ipv6verify/test --cli-binary-format raw-in-base64-out --payload '{"seq":4,"phase":"policy-effective"}'
Here is the line for this message from the output of show-ingest-logs.sh. The source was within the range, and it was delivered without being denied.
2406:da33:4000:0:8bd6:dc2c:1c3d:4cfb {"seq":4,"phase":"policy-effective"}
When I sent a curl request to the API from my local environment, which has an IPv6 address outside the range, it was denied with a 403.
curl -6 -s -m 15 -X POST -d '{"test":"curl-v6-after-retry"}' -w '\nhttp=%{http_code}\n' https://iot-v6.example.com/ingest
The 403 response is as follows.
{"Message":"User: anonymous is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:ap-northeast-1:************:<REST API の ID>/v1/POST/ingest with an explicit deny in a resource-based policy"}
http=403
Summary
The IPv6 ranges used by the AWS IoT Core HTTP rule action have been published per region.
Using API Gateway as a stand-in for the receiving end of an HTTP rule action, I confirmed that a resource policy can allow only IoT Core in the Tokyo region as the connection source.
If your receiving side for the AWS IoT Core HTTP rule action can accept IPv6, configuring it to allow only the per-region IPv6 ranges published this time lets you reject connections from anything other than AWS IoT Core in that region.
If you want to restrict the connection source to AWS IoT Core in a specific region, give this update a try.
