Skip to content

fix(cloudformation): derive ARN partitions from the region and mint ARNs with the services' builders - #2591

Merged
vieiralucas merged 6 commits into
mainfrom
fix/arn-partition-cloudformation
Sep 29, 2026
Merged

vieiralucas merged 6 commits into
mainfrom
fix/arn-partition-cloudformation

Conversation

@vieiralucas

@vieiralucas vieiralucas commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Last PR of the ARN partition campaign (#2569, #2570, #2572, #2574, #2577, #2578, #2580, #2590). With every service now minting ARNs in the region's partition (aws-cn for cn-*, aws-us-gov for us-gov-*, ISO partitions), the CloudFormation provisioner now produces exactly the ARNs the service APIs produce, so stack-created and API-created resources agree (several services key state by ARN).

Partition-aware provisioner

  • Stack, stack-set (incl. legacy migration), change-set, type, hook, generated-template and scan ARNs use the stack/request region's partition. extras.rs ARNs that were pinned to us-east-1 now carry the request region (commercial-region change, AWS-faithful).
  • UpdateStackSet defaults the administration role in the stack set's own partition. SAM managed policies and integration URIs use ${AWS::Partition}.
  • Parsers (parse_log_group_name, Lambda function/alias/layer ARNs) accept any known partition.

Service builders instead of re-formatted ARNs
DynamoDB, RDS (DB instances, clusters, parameter/option groups, proxies), ElastiCache, EFS, Lambda (functions, versions, aliases, layers), Step Functions, ECS, ELBv2 (load balancers, target groups, trust stores, and listeners/rules derived from their parent ARN), Batch, Application Auto Scaling, Auto Scaling, EMR, SageMaker, ACM, ACM PCA, Cognito, Logs, CloudFront, Cloud Map, CodeBuild, CodeCommit, CodePipeline, CodeArtifact, CodeDeploy, Elastic Beanstalk, AppSync, WAFv2, Organizations, SNS, EventBridge, CloudWatch, SSM, Athena, and default KMS key ARNs via the KMS form.

Fidelity fixes in commercial regions (AWS-faithful)

  • Batch compute environments / job queues: ARNs no longer carry a -<uuid> suffix, so the Batch API finds stack-created ones by their ARN.
  • Organizations OUs/policies go through the service (create_ou/create_policy/attach_policy): duplicate names, unsupported/unknown types and malformed content fail with the API's errors; policy ARNs use the service's path segment; the resource-policy ARN matches DescribeResourcePolicy.
  • Regional WAFv2 ARNs use the regional/ segment; CLOUDFRONT scope uses the partition's global region (cn-northwest-1 in China).
  • Gateway load balancers get gwy/ ARNs.
  • Application Auto Scaling default roles are the documented service-linked role names (no doubled prefix, no invented _Default; EMR uses EMR_AutoScaling_DefaultRole).
  • Lambda layer version numbers are never reused after a delete, including when the last version is deleted (also in the Lambda API).

Known limitation: state persisted by a cn/gov server before the campaign keeps arn:aws: rows. No surface changes.

Test plan

  • China-region tests: stack/change-set/stack-set ARNs, provisioner ARNs across services, china_stack_arns_match_the_service_builders (SNS, EventBridge, CloudWatch, SSM, Athena, EFS/Timestream default keys), Organizations OU following the org's partition, WAF regional/CLOUDFRONT, ELBv2 listener derivation, Batch lookup by ARN, Organizations validation errors, layer version numbering, Application Auto Scaling default roles.
  • cargo test -p fakecloud-cloudformation (486), cargo check --workspace --all-targets, clippy -D warnings, cargo fmt --check, scripts/publish-crates.sh --check.

Summary by cubic

Finishes the ARN-partition campaign: the CloudFormation provisioner now derives partitions from the request region and mints resource ARNs using the owning services' builders, so stack-created and API-created resources carry identical ARNs.

Partition-aware provisioner

  • Stack, stack-set, change-set, type, hook, generated-template, and scan ARNs take the stack or request region's partition instead of arn:aws; extras pinned to us-east-1 now follow the request region (a commercial-region behavior change, AWS-faithful).
  • Organizations OUs and policies follow the organization's partition; SAM managed policies and integration URIs use ${AWS::Partition}.
  • Log-group and Lambda function/alias/layer ARN parsers accept any known partition.

Fidelity fixes in commercial regions

  • Batch compute environments and job queues drop the -<uuid> ARN suffix so the Batch API finds stack-created ones by ARN.
  • Organizations OUs and policies now go through the service's validation and fail with the API's error codes.
  • Regional WAFv2 ARNs use the regional/ segment and CLOUDFRONT uses the partition's global region.
  • Lambda layer version numbers are never reused after a delete, even when the last version is removed.
  • Application Auto Scaling defaults each namespace to its documented service-linked role instead of invented names.

Known limitation: state persisted by a cn/gov server before this campaign keeps arn:aws: rows; no surface changes.

Written for commit 7bce3d7. Summary will update on new commits.

Review in cubic

fakecloud-cloudformation: stack, change-set, stack-set, type, hook and
generated-template ARNs and every ARN the resource provisioner mints for
other services take the partition of the stack's region; the
UpdateStackSet default administration role follows the stack set's own
partition, Organizations OUs/policies follow the organization's, and
SAM-synthesized API ARNs use ${AWS::Partition}. Log-group, Lambda
function/alias and layer ARN parsers accept any partition.
- ResourceProvisioner::regional_arn builds the stack-region ARNs; ECS
  cluster/service/task definition, Kinesis stream and Step Functions state
  machine ARNs come from their service crates' builders.
- CodeDeploy and Elastic Beanstalk ARN copies stay byte-identical to their
  service crates, whose builders are private.
- CLOUDFRONT-scoped WAFv2 ARNs use the partition's implicit global region.
- SAM managed-policy ARNs use ${AWS::Partition}.
- arn_partition is replaced by fakecloud_aws::arn::partition_of; redundant
  with_partition calls after Arn::global_in are gone; the generated-template
  ARN in DescribeGeneratedTemplate goes through Arn::regional.
…ces' builders

Provisioners for DynamoDB, RDS, ElastiCache, EFS, Lambda, Step Functions,
ECS, ELBv2, Batch, Application Auto Scaling, Auto Scaling, EMR, SageMaker,
ACM, ACM PCA, Cognito, Logs, CloudFront, Service Discovery, CodeBuild,
CodeCommit, CodePipeline, CodeArtifact, CodeDeploy, Elastic Beanstalk,
AppSync and WAFv2 now call those crates' ARN builders, so a stack's
resources carry exactly the ARNs the service APIs mint. Organizations are
bootstrapped in the stack region's partition and OU/policy ARNs come from
the organization. Default KMS key ARNs use fakecloud_kms::kms_key_arn.
Regional WAFv2 ARNs now use the `regional/` scope segment.
…anizations, ELBv2 and layers

- Batch compute environments and job queues get the service's
  `compute-environment/<name>` / `job-queue/<name>` ARNs, so the stack's
  Ref ARN addresses them through the Batch API.
- Organizations OUs and policies go through OrganizationState::create_ou,
  create_policy and attach_policy, so the service's validation and policy
  type path segments apply and failures carry the API error codes; the
  resource policy uses the service's id and ARN.
- ELBv2 listener and rule ARNs derive from the parent load balancer and
  listener ARNs through new fakecloud_elbv2::listener_arn and
  listener_rule_arn helpers the service now shares.
- Application Auto Scaling defaults each namespace to its documented
  service-linked role (EMR to EMR_AutoScaling_DefaultRole) instead of
  invented names.
- Lambda layer version numbers are never reused after a deletion, in the
  service and the provisioner.
- RDS instances, the Auto Scaling service-linked role and the CodeArtifact
  asset bucket come from their service crates' builders.
… the API

- Deleting a stack's last LayerVersion keeps the layer entry, as the
  API's DeleteLayerVersion does, so a replaced or recreated layer version
  never reuses a number.
- AWS::Organizations::Policy runs CreatePolicy's Type checks first (now
  shared as fakecloud_organizations::check_create_policy_type), failing
  with InvalidInputException / PolicyTypeNotAvailableForOrganizationException.
- Move the Auto Scaling service-linked role builder above autoscaling_arn's
  doc comment.
…Athena ARNs with their builders

The SNS topic, EventBridge rule and bus, CloudWatch alarm, SSM parameter
and Athena workgroup/data catalog provisioners now call the service
crates' ARN builders, so a China stack's resources carry the same ARNs
the APIs mint. A test pins those and the EFS/Timestream default KMS key
ARNs against the services.
@vieiralucas
vieiralucas merged commit e7f56aa into main Sep 29, 2026
158 checks passed
@vieiralucas
vieiralucas deleted the fix/arn-partition-cloudformation branch September 29, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant