aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
176 stars 61 forks source link

Error on creating sandbox: This AWS account and region has not been bootstrapped #1496

Closed oe-bayram closed 5 months ago

oe-bayram commented 6 months ago

Environment information

System:
  OS: Windows 11 10.0.22631
  CPU: ...
  Memory: ...
Binaries:
  Node: 18.16.0 - ...
  Yarn: 1.22.19 - ...
  npm: 9.5.1 - ...
  pnpm: 9.1.0 - ...
NPM Packages:
  @aws-amplify/backend: 1.0.0
  @aws-amplify/backend-cli: 1.0.1
  aws-amplify: 6.2.0
  aws-cdk: 2.140.0
  aws-cdk-lib: 2.140.0
  typescript: 5.4.5
AWS environment variables:
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variables

Description

When I try to create a sandbox I always get his error message:

This AWS account and region has not been bootstrapped.
Caused By:
 ❌ Deployment failed: Error: amplify-amplifyvitereacttemplate-spieleladen-sandbox-2b171ff521: SSM parameter /cdk-bootstrap/hnb659fds/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)
    at Deployments.validateBootstrapStackVersion (C:\Users\Goldweb\Spieleladen\preistool\node_modules\aws-cdk\lib\index.js:438:12210)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Deployments.buildSingleAsset (C:\Users\Goldweb\Spieleladen\preistool\node_modules\aws-cdk\lib\index.js:438:10975)
    at async Object.buildAsset (C:\Users\Goldweb\Spieleladen\preistool\node_modules\aws-cdk\lib\index.js:438:197148)     
    at async C:\Users\Goldweb\Spieleladen\preistool\node_modules\aws-cdk\lib\index.js:438:181290
amplify-amplifyvitereacttemplate-spieleladen-sandbox-2b171ff521: SSM parameter /cdk-bootstrap/hnb659fds/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)

Resolution: Run `cdk bootstrap aws://{YOUR_ACCOUNT_ID}/{YOUR_REGION}` locally to resolve this.

[Sandbox] Watching for file changes...

I bootstrapped the environment in both ways: using cdk bootstrap ... and the bootstrap process via the console.

ykethan commented 6 months ago

Hey @oe-bayram, could you ensure the profile/account that bootstrapped is being passed with sandbox command using --profile. https://docs.amplify.aws/react/reference/cli-commands/#ampx-sandbox-Usage

oe-bayram commented 6 months ago

Yes, since I have multiple profiles, I have to use --profile but I still get the error message.

edwardfoyle commented 6 months ago

Another thing to check is if the profile is configured to use the same region that you have bootstrapped?

oe-bayram commented 6 months ago

Yes, I checked it already:

[profile preistool]
sso_session = preistool
sso_account_id = XYZ
sso_role_name = amplify-policy
region = eu-central-1
[sso-session preistool]
sso_start_url = https://XYZ.awsapps.com/start
sso_region = eu-central-1
sso_registration_scopes = sso:account:access
edwardfoyle commented 6 months ago

Can you confirm that an SSM parameter named /cdk-bootstrap/hnb659fds/version exists in the eu-central-1 region? If not, then that region has not been successfully bootstrapped.

oe-bayram commented 6 months ago

Yes this parameter exists and has the value 20

oe-bayram commented 6 months ago

What I've found out so far:

If the region is not set in the config for the profile then I get the error mentioned before.

If I set it in the config then I get another error message:

[preistool]
region = eu-central-1

Error message:

Unable to build the Amplify backend definition.
Caused By: TypeError: Cannot redefine property: preistool
    at Function.defineProperty (<anonymous>)

Resolution: Check your backend definition in the `amplify` folder for syntax and type errors.
edwardfoyle commented 6 months ago

I think your config file may be incorrect. The region config for a named profile should look like

[profile preistool]
region=eu-central-1

See here for more details on the format of the config file: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-format

oe-bayram commented 6 months ago

Now I'm using an IAM user profile with AdminAccess:

In credentials:

[Spieleladen]
aws_access_key_id=MY_ACCESS_KEY_ID
aws_secret_access_key=MY_SECRET_ACCESS_KEY

In config:

[profile Spieleladen]
region=eu-central-1

Now I'm getting the same error message an dthis warning before that: current credentials could not be used to assume 'arn:aws:iam::ACCOUNT_ID:role/cdk-hnb659fds-deploy-role-ACCOUNT_ID-eu-central-1', but are for the right account. Proceeding anyway. where the ACCOUNT_ID is from another profile.

I have deleted all the other profiles from the credentials and config but I still get the warning and the error message.

edwardfoyle commented 5 months ago

Do you have the AWS_PROFILE, AWS_REGION, or AWS_DEFAULT_REGION environment variable set? Amplify uses the default AWS credential loading strategy which is detailed here: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#configure-precedence. If AWS_REGION or AWS_DEFAULT_REGION is set, that would take precedence over the region in the config file.

oe-bayram commented 5 months ago

No environment variables were set before but setting AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY explicitly did help. Thanks so far.

truejordan commented 2 months ago

I have this issue as well but on a separate aws account. The credentials I use are basically identical other that their names. I can run the amplify sandbox in one account but not the other.

Ive attempted this but it does not work: Resolution: Run cdk bootstrap aws://{My_ACCOUNT_ID}/{My_REGION}

truejordan commented 2 months ago

I deleted the stack in cloud formation and initialised it again with npx ampx sandbox that seem to do the trick !