kapilt: fwiw the other case this pops up is with c7n-org but it looks like that already has some detection of user var interpolation `{}` to avoid adding the suffix.
diff --git a/c7n/resources/aws.py b/c7n/resources/aws.py
index b8acc3716..2b2bdd63b 100644
--- a/c7n/resources/aws.py
+++ b/c7n/resources/aws.py
@@ -639,7 +639,7 @@ class AWS(Provider):
         """Return a set of policies targetted to the given regions.
 
         Supports symbolic regions like 'all'. This will automatically
-        filter out policies if their being targetted to a region that
+        filter out policies if they are being targetted to a region that
         does not support the service. Global services will target a
         single region (us-east-1 if only all specified, else first
         region in the list).
@@ -705,6 +705,8 @@ class AWS(Provider):
 
 
 def join_output(output_dir, suffix):
+    if '{region}' in output_dir:
+        return output_dir.rstrip('/')
     if output_dir.endswith('://'):
         return output_dir + suffix
     return output_dir.rstrip('/') + '/%s' % suffix

aws - custom log/output directories with --region all
**Describe the bug**

--region all unconditionally suffixes a region, even though it may already be present in a custom output/format string. it should detect output region usage and avoid the suffix.


diff --git a/tests/test_policy.py b/tests/test_policy.py
index d2908979c..0ca02f058 100644
--- a/tests/test_policy.py
+++ b/tests/test_policy.py
@@ -478,7 +478,8 @@ class TestPolicyCollection(BaseTest):
             config=Config.empty(regions=["us-east-1", "us-west-2"]),
         )
 
-        collection = AWS().initialize_policies(original, Config.empty(regions=["all"]))
+        collection = AWS().initialize_policies(
+            original, Config.empty(regions=["all"], output_dir="/test/output/"))
         self.assertEqual(len(collection.resource_types), 2)
         s3_regions = [p.options.region for p in collection if p.resource_type == "s3"]
         self.assertTrue("us-east-1" in s3_regions)
@@ -486,13 +487,23 @@ class TestPolicyCollection(BaseTest):
         iam = [p for p in collection if p.resource_type == "iam-user"]
         self.assertEqual(len(iam), 1)
         self.assertEqual(iam[0].options.region, "us-east-1")
+        self.assertEqual(iam[0].options.output_dir, "/test/output/us-east-1")
+
+        # Don't append region when it's already in the path.
+        collection = AWS().initialize_policies(
+            original, Config.empty(regions=["all"], output_dir="/test/{region}/output/"))
+        self.assertEqual(len(collection.resource_types), 2)
+        iam = [p for p in collection if p.resource_type == "iam-user"]
+        self.assertEqual(iam[0].options.region, "us-east-1")
+        self.assertEqual(iam[0].options.output_dir, "/test/{region}/output")
 
         collection = AWS().initialize_policies(
-            original, Config.empty(regions=["eu-west-1", "eu-west-2"])
+            original, Config.empty(regions=["eu-west-1", "eu-west-2"], output_dir="/test/output/")
         )
         iam = [p for p in collection if p.resource_type == "iam-user"]
         self.assertEqual(len(iam), 1)
         self.assertEqual(iam[0].options.region, "eu-west-1")
+        self.assertEqual(iam[0].options.output_dir, "/test/output/eu-west-1")
         self.assertEqual(len(collection), 3)
 
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
apipkg==1.5
appdirs==1.4.3
argcomplete==1.11.1
attrs==19.3.0
aws-xray-sdk==2.4.3
bleach==3.1.4
boto3==1.12.36
botocore==1.15.36
-e git+https://github.com/cloud-custodian/cloud-custodian.git@80a8bbdb99472241754781a08945df9fe6bcd73c#egg=c7n
certifi==2020.4.5.1
cffi==1.14.0
chardet==3.0.4
coverage==5.0.4
cryptography==2.9
distlib==0.3.0
docutils==0.15.2
entrypoints==0.3
exceptiongroup==1.2.2
execnet==1.7.1
filelock==3.0.12
flake8==3.7.9
future==0.18.2
idna==2.9
importlib-metadata==1.6.0
iniconfig==2.0.0
jeepney==0.4.3
jmespath==0.9.5
jsonpatch==1.25
jsonpickle==1.3
jsonpointer==2.0
jsonschema==3.2.0
keyring==21.2.0
mccabe==0.6.1
mock==4.0.2
more-itertools==8.2.0
multidict==4.7.5
packaging==20.3
pkginfo==1.5.0.1
placebo==0.9.0
pluggy==0.13.1
psutil==5.7.0
py==1.8.1
pycodestyle==2.5.0
pycparser==2.20
pyflakes==2.1.1
Pygments==2.6.1
pyparsing==2.4.7
pyrsistent==0.16.0
pytest==7.4.4
pytest-asyncio==0.21.2
pytest-cov==2.8.1
pytest-forked==1.1.3
pytest-mock==3.11.1
pytest-xdist==1.31.0
python-dateutil==2.8.1
PyYAML==5.3.1
readme-renderer==25.0
requests==2.23.0
requests-toolbelt==0.9.1
s3transfer==0.3.3
SecretStorage==3.1.2
six==1.14.0
tabulate==0.8.7
toml==0.10.0
tomli==2.0.1
tox==3.14.6
tqdm==4.45.0
twine==3.1.1
typing_extensions==4.7.1
urllib3==1.25.8
vcrpy==4.0.2
virtualenv==20.0.16
wcwidth==0.1.9
webencodings==0.5.1
wrapt==1.12.1
yarl==1.4.2
zipp==3.1.0

name: cloud-custodian
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - apipkg==1.5
      - appdirs==1.4.3
      - argcomplete==1.11.1
      - attrs==19.3.0
      - aws-xray-sdk==2.4.3
      - bleach==3.1.4
      - boto3==1.12.36
      - botocore==1.15.36
      - c7n==0.9.0
      - certifi==2020.4.5.1
      - cffi==1.14.0
      - chardet==3.0.4
      - coverage==5.0.4
      - cryptography==2.9
      - distlib==0.3.0
      - docutils==0.15.2
      - entrypoints==0.3
      - exceptiongroup==1.2.2
      - execnet==1.7.1
      - filelock==3.0.12
      - flake8==3.7.9
      - future==0.18.2
      - idna==2.9
      - importlib-metadata==1.6.0
      - iniconfig==2.0.0
      - jeepney==0.4.3
      - jmespath==0.9.5
      - jsonpatch==1.25
      - jsonpickle==1.3
      - jsonpointer==2.0
      - jsonschema==3.2.0
      - keyring==21.2.0
      - mccabe==0.6.1
      - mock==4.0.2
      - more-itertools==8.2.0
      - multidict==4.7.5
      - packaging==20.3
      - pkginfo==1.5.0.1
      - placebo==0.9.0
      - pluggy==0.13.1
      - psutil==5.7.0
      - py==1.8.1
      - pycodestyle==2.5.0
      - pycparser==2.20
      - pyflakes==2.1.1
      - pygments==2.6.1
      - pyparsing==2.4.7
      - pyrsistent==0.16.0
      - pytest==7.4.4
      - pytest-asyncio==0.21.2
      - pytest-cov==2.8.1
      - pytest-forked==1.1.3
      - pytest-mock==3.11.1
      - pytest-xdist==1.31.0
      - python-dateutil==2.8.1
      - pyyaml==5.3.1
      - readme-renderer==25.0
      - requests==2.23.0
      - requests-toolbelt==0.9.1
      - s3transfer==0.3.3
      - secretstorage==3.1.2
      - six==1.14.0
      - tabulate==0.8.7
      - toml==0.10.0
      - tomli==2.0.1
      - tox==3.14.6
      - tqdm==4.45.0
      - twine==3.1.1
      - typing-extensions==4.7.1
      - urllib3==1.25.8
      - vcrpy==4.0.2
      - virtualenv==20.0.16
      - wcwidth==0.1.9
      - webencodings==0.5.1
      - wrapt==1.12.1
      - yarl==1.4.2
      - zipp==3.1.0
prefix: /opt/conda/envs/cloud-custodian

tests/test_policy.py::TestPolicyCollection::test_policy_region_expand_global
tests/test_policy.py::PolicyMetaLint::test_filter_action_additional tests/test_policy.py::PolicyMetaLint::test_filter_action_type tests/test_policy.py::PolicyMetaLint::test_policy_detail_spec_permissions tests/test_policy.py::PolicyMetaLint::test_policy_missing_provider_session tests/test_policy.py::PolicyMetaLint::test_resource_arn_info tests/test_policy.py::PolicyMetaLint::test_resource_arn_override_generator tests/test_policy.py::PolicyMetaLint::test_resource_augment_universal_mask tests/test_policy.py::PolicyMetaLint::test_resource_legacy_type tests/test_policy.py::PolicyMetaLint::test_resource_meta_with_class tests/test_policy.py::PolicyMetaLint::test_resource_name tests/test_policy.py::PolicyMetaLint::test_resource_permissions tests/test_policy.py::PolicyMetaLint::test_resource_shadow_source_augment tests/test_policy.py::PolicyMetaLint::test_resource_type_empty_metadata tests/test_policy.py::PolicyMetaLint::test_resource_universal_taggable_arn_type tests/test_policy.py::PolicyMetaLint::test_schema tests/test_policy.py::PolicyMetaLint::test_schema_plugin_name_mismatch tests/test_policy.py::PolicyMetaLint::test_schema_serialization tests/test_policy.py::PolicyMeta::test_policy_detail_spec_permissions tests/test_policy.py::PolicyMeta::test_policy_manager_custom_permissions tests/test_policy.py::TestPolicyCollection::test_expand_partitions tests/test_policy.py::TestPolicyCollection::test_policy_expand_group_region tests/test_policy.py::TestPolicy::test_child_resource_trail_validation tests/test_policy.py::TestPolicy::test_file_not_found tests/test_policy.py::TestPolicy::test_get_resource_manager tests/test_policy.py::TestPolicy::test_load_policy_validation_error tests/test_policy.py::TestPolicy::test_policy_name_and_resource_type_filtering tests/test_policy.py::TestPolicy::test_policy_resource_limit_and_percent tests/test_policy.py::TestPolicy::test_policy_resource_limits tests/test_policy.py::TestPolicy::test_policy_resource_limits_count tests/test_policy.py::TestPolicy::test_policy_resource_limits_with_filter tests/test_policy.py::TestPolicy::test_policy_validation tests/test_policy.py::TestPolicy::test_policy_variable_interpolation tests/test_policy.py::TestPolicy::test_policy_variable_precedent tests/test_policy.py::TestPolicy::test_policy_with_role_complete tests/test_policy.py::TestPolicy::test_validate_policy_start_stop tests/test_policy.py::PolicyConditionsTest::test_boolean_and_blocks tests/test_policy.py::PolicyConditionsTest::test_boolean_not_blocks tests/test_policy.py::PolicyConditionsTest::test_boolean_or_blocks tests/test_policy.py::PolicyConditionsTest::test_env_var_extension tests/test_policy.py::PolicyConditionsTest::test_event_filter tests/test_policy.py::PolicyExecutionModeTest::test_get_logs_unimplemented tests/test_policy.py::PolicyExecutionModeTest::test_run_unimplemented tests/test_policy.py::LambdaModeTest::test_tags_injection tests/test_policy.py::LambdaModeTest::test_tags_validation tests/test_policy.py::PullModeTest::test_is_runnable_dates tests/test_policy.py::PullModeTest::test_is_runnable_mismatch_region tests/test_policy.py::PullModeTest::test_is_runnable_parse_dates tests/test_policy.py::PullModeTest::test_skip_when_region_not_equal tests/test_policy.py::PhdModeTest::test_validation tests/test_policy.py::GuardModeTest::test_ec2_guard_event_pattern tests/test_policy.py::GuardModeTest::test_ec2_instance_guard tests/test_policy.py::GuardModeTest::test_iam_guard_event_pattern tests/test_policy.py::GuardModeTest::test_iam_user_access_key_annotate tests/test_policy.py::GuardModeTest::test_lambda_policy_validate_name tests/test_policy.py::GuardModeTest::test_unsupported_resource
c7n/resources/aws.py
c7n/resources/aws.py