I had a working environment and I wanted to add a new environment using aws amplify cli. I used the
amplify init
command and added a new env which is in separate account and it got create successfully. I tried:
amplify add env
for adding env in the same account but I get the following error:
An error occurred when creating the CloudFormation stack
The following resources failed to deploy:
Resource Name: AuthRole (AWS::IAM::Role)
Event Type: create
Reason: ASD-amplify-authrole-{envName} already exists in stack arn:aws:cloudformation:xxx:xxx:stack/amplify-xx-xxx-xx/xxx
Initialization of project failed
Name: AuthRole (AWS::IAM::Role), Event Type: create, Reason: ASD-amplify-authrole-{envName} already exists in stack arn:aws:cloudformation:xxx:xxx:stack/amplify-xx-xxx-xx/xxx, IsCustomResource: false
It is copying the auth role name as that of working previous env in both cases.
for the separate account it gets created but in the same it found it already existing.
I have an overriden.ts file generated using amplify override project which looks like this.
export function override(resources: AmplifyRootStackTemplate) {
const authRole = resources.authRole;
authRole.roleName = `${PRE_FIX}-amplify-authrole-${ENV_NAME}`;
if (isCrossAccount) {
const basePolicies = Array.isArray(authRole.policies)
? authRole.policies
: [authRole.policies];
authRole.policies = [
...basePolicies,
{
policyName: `${PRE_FIX}-amplify-authrole-assumerole-policy`,
policyDocument: {
Version: "2012-10-17",
Statement: [
{
Action: "sts:AssumeRole",
Resource: `arn:aws:iam::${ACCOUNT_ID}:role/${PRE_FIX}-xxx-${POST_FIX}`,
Effect: "Allow",
},
],
},
},
];
}
}
I pass these variables isCrossAccount, ENV_NAME, PRE_FIX, POST_FIX, ACCOUNT_ID using the env.ts file that I created in the same folder and import as "./env".
I tried updating the env.ts file and hard coded the name of ENV_NAME, PRE_FIX, POST_FIX, ACCOUNT_ID and use them but it always picks the values as from older env.