Skip to content

fix(amplify-category-storage): make IAM policy names environment-specific - #14962

Open
w3lld1 wants to merge 2 commits into
aws-amplify:devfrom
w3lld1:category-storage/unique-policy-names-14961
Open

fix(amplify-category-storage): make IAM policy names environment-specific#14962
w3lld1 wants to merge 2 commits into
aws-amplify:devfrom
w3lld1:category-storage/unique-policy-names-14961

Conversation

@w3lld1

@w3lld1 w3lld1 commented Jul 15, 2026

Copy link
Copy Markdown

Description of changes

I made generated S3 IAM policy names environment-specific by appending the current Amplify environment name to the existing policy UUID. This prevents two environments that share imported auth roles from trying to manage identically named inline policies.

I also added a focused regression test for the generated policy names and updated the existing stack-transform expectations.

Issue #, if available

Fixes #14961

Description of how you validated changes

  • yarn lerna run build --scope @aws-amplify/amplify-category-storage --include-dependencies --concurrency 4
  • node ../../node_modules/jest/bin/jest.js --runInBand --coverage=false from packages/amplify-category-storage (15 suites, 48 tests)
  • Prettier and ESLint checks for all changed TypeScript files

I did not run cloud E2E tests or the macOS CI job locally.

Checklist

  • PR description included
  • yarn test passes for the changed package
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@w3lld1
w3lld1 requested a review from a team as a code owner July 15, 2026 19:18
this.cfnInputParams.s3UploadsPolicy = `Uploads_policy_${userInput.policyUUID}`;
this.cfnInputParams.authPolicyName = `s3_amplify_${userInput.policyUUID}`;
this.cfnInputParams.unauthPolicyName = `s3_amplify_${userInput.policyUUID}`;
const policyNameSuffix = `${userInput.policyUUID}_${this.context.amplify.getEnvInfo().envName}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New unguarded getEnvInfo().envName dependency yields '_undefined' names or a throw when env info is absent

Name generation now hard-depends on this.context.amplify.getEnvInfo().envName, a call this method never made before (the existing test had to add getEnvInfo to its mock context). There is no check that getEnvInfo() returns an object or that envName is non-empty.

const policyNameSuffix = `${userInput.policyUUID}_${this.context.amplify.getEnvInfo().envName}`;

Why it matters: getEnvInfo() returns no/blank envName (uninitialized env, headless/export/mock paths) → suffix becomes ${uuid}_undefined → all such deployments again share one policy name and re-collide (the very bug being fixed), OR getEnvInfo() throws → transform now fails on a path that previously succeeded (regression).

Suggestion: Read envName once, assert it is a non-empty string, and fail fast with a clear AmplifyError if it is missing, we can add a test for the missing-envName case alongside the happy-path test.

…olicy names

The env-specific policy-name suffix read `getEnvInfo().envName` directly. When
env info is absent or blank (uninitialized env / headless / export paths) the
suffix silently became `..._undefined`, which puts every such deployment back on
one shared policy name and re-collides -- the exact bug this change fixes -- or
threw an opaque error on a path that previously succeeded.

Read the env name once and validate it: fail fast with a clear
`EnvironmentNotInitializedError` when it is missing or empty, so names never
degrade to a shared `_undefined` suffix.

Adds a regression test covering the missing-envName case alongside the existing
happy-path test.
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.

Storage deploy fails with 'Policy resource was already managed by another stack' after CFN enforcement change (Jan 2026)

2 participants