在AWS Amplify构建Next.js应用失败:初始化staging环境遇Access Denied
AWS Amplify构建Next.js应用失败:Access Denied(初始化staging环境)
跟随《Build a Full-Stack React Application》教程操作,将代码推送到GitHub后,在AWS Amplify上构建Next.js应用时失败。构建日志显示无法初始化staging平台,提示Access Denied,怀疑是目录配置错误或AWS账户权限不足。
构建日志
# Starting phase: build 2023-05-03T02:31:47.363Z [INFO]: [33mNote: It is recommended to run this command from the root of your app directory[39m 2023-05-03T02:31:47.908Z [WARNING]: - Initializing your environment: staging 2023-05-03T02:31:47.994Z [WARNING]: ✖ Initializing your environment: staging 2023-05-03T02:31:47.994Z [WARNING]: ✖ There was an error initializing your environment. 2023-05-03T02:31:47.995Z [INFO]: 🛑 Could not initialize platform for 'staging': Access Denied Resolution: Review the error message and stack trace for additional information. 2023-05-03T02:31:48.007Z [INFO]: 2023-05-03T02:31:48.007Z [INFO]: Session Identifier: 8fed5aa7-be23-4e0f-81a7-2d217bbbd640 2023-05-03T02:31:48.056Z [ERROR]: !!! Build failed 2023-05-03T02:31:48.056Z [INFO]: Please check the supported SSR features to find if your build failure is related to an unsupported feature. You may also find this troubleshooting guide useful. 2023-05-03T02:31:48.056Z [ERROR]: !!! Non-Zero Exit Code detected 2023-05-03T02:31:48.056Z [INFO]: # Starting environment caching... 2023-05-03T02:31:48.057Z [INFO]: # Environment caching completed Terminating logging...
package.json配置
{ "name": "amplifyapp", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@aws-amplify/ui-react": "^4.6.0", "autoprefixer": "10.4.14", "aws-amplify": "^5.1.4", "eslint": "8.39.0", "eslint-config-next": "13.3.4", "next": "13.3.4", "postcss": "8.4.23", "react": "18.2.0", "react-dom": "18.2.0", "tailwindcss": "3.3.2" } }
排查与解决步骤
检查AWS账户权限
确认当前AWS账户的Amplify服务角色拥有初始化环境所需的权限,包括amplify:CreateEnvironment、amplify:UpdateEnvironment等核心权限。若使用自动生成的角色,检查角色的权限策略是否完整,未被自定义规则限制。核对项目目录配置
日志提示“建议从应用根目录运行命令”,需确认Amplify控制台中设置的工作目录是否为GitHub仓库的根目录。若项目嵌套在子目录中,需在Amplify构建设置里指定正确的工作路径。同步Amplify环境配置
确保本地的Amplify staging环境配置与云端一致,可尝试在本地执行amplify push重新推送环境配置,或在Amplify控制台中删除现有staging环境后重新创建。验证本地构建可用性
在本地执行npm run build,确认项目本身能正常完成构建,排除代码或依赖导致的构建失败问题。
内容的提问来源于stack exchange,提问作者ajunx8
相关产品推荐
相关产品推荐

