在 Amplify 上部署时,找不到 AWS 访问凭证错误

Sud*_*shu 2 github amazon-web-services aws-amplify aws-amplify-cli

我正在尝试在放大上部署我的反应应用程序。我正在使用存储、身份验证和 GraphQL API。但是我在推送代码时收到此错误。构建失败。

在本地主机上运行时,一切都按预期工作。

2023-05-20T09:21:17.184Z [INFO]: # Cloning repository: git@github.com:zyz/xyz
2023-05-20T09:21:19.101Z [INFO]: 
2023-05-20T09:21:19.103Z [INFO]: Cloning into 'zeeepy'...
2023-05-20T09:21:19.104Z [INFO]: # Switching to commit: bd45c7afa30c9e71643a0e0a2991d0fc8440c7aa
2023-05-20T09:21:19.124Z [INFO]: Note: switching to 'bd45c7afa30c9e71643a0e0a2991d0fc8440c7aa'.
                                 You are in 'detached HEAD' state. You can look around, make experimental
                                 changes and commit them, and you can discard any commits you make in this
                                 state without impacting any branches by switching back to a branch.
                                 If you want to create a new branch to retain commits you create, you may
                                 do so (now or later) by using -c with the switch command. Example:
                                 git switch -c <new-branch-name>
                                 Or undo this operation with:
                                 git switch -
                                 Turn off this advice by setting config variable advice.detachedHead to false
                                 HEAD is now at bd45c7a Backend integrated
2023-05-20T09:21:19.180Z [INFO]: Successfully cleaned up Git credentials
2023-05-20T09:21:19.180Z [INFO]: # Checking for Git submodules at: /codebuild/output/src242373753/src/zeeepy/.gitmodules
2023-05-20T09:21:19.189Z [INFO]: # Retrieving environment cache...
2023-05-20T09:21:19.796Z [INFO]: # Retrieved environment cache
2023-05-20T09:21:19.797Z [INFO]: ---- Setting Up SSM Secrets ----
2023-05-20T09:21:19.797Z [INFO]: SSM params {"Path":"/amplify/d3ia74jrzqfroo/main/","WithDecryption":true}
2023-05-20T09:21:19.836Z [WARNING]: !Failed to set up process.env.secrets
2023-05-20T09:21:42.406Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 10.5.2 to 12.0.0...
2023-05-20T09:22:02.567Z [INFO]: # Done patching NPM package '@aws-amplify/cli' to version 12.0.0
2023-05-20T09:22:02.630Z [INFO]: # Retrieving cache...
2023-05-20T09:22:05.748Z [INFO]: # Extracting cache...
2023-05-20T09:22:10.438Z [INFO]: # Extraction completed
2023-05-20T09:22:11.441Z [INFO]: # Retrieved cache
2023-05-20T09:22:15.475Z [INFO]: ## Starting Backend Build
                                 # Starting phase: build
2023-05-20T09:22:17.637Z [INFO]: [33mNote: It is recommended to run this command from the root of your app directory[39m
2023-05-20T09:22:17.652Z [INFO]:  AWS access credentials can not be found.
2023-05-20T09:22:17.652Z [INFO]: Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
2023-05-20T09:22:17.696Z [INFO]: 
2023-05-20T09:22:17.697Z [INFO]: Session Identifier: 5668b0c6-8dc5-4dcd-8b00-38754fa06b84
2023-05-20T09:22:17.715Z [ERROR]: !!! Build failed
2023-05-20T09:22:17.716Z [ERROR]: !!! Non-Zero Exit Code detected
2023-05-20T09:22:17.716Z [INFO]: # Starting environment caching...
2023-05-20T09:22:17.716Z [INFO]: # Uploading environment cache artifact...
2023-05-20T09:22:17.824Z [INFO]: # Uploaded environment cache artifact
2023-05-20T09:22:17.824Z [INFO]: # Environment caching completed
Terminating logging...

Run Code Online (Sandbox Code Playgroud)

我尝试使用 amplify configure 重新配置,并尝试重新连接 github。什么都不起作用。

能否请你帮忙?

感谢和问候

Sup*_*ool 7

您需要添加服务角色来构建后端。

以下是步骤-

  1. 转到 IAM 管理器
  2. 单击左侧导航栏中的角色
  3. 点击创建角色
  4. 在角色选择屏幕中,找到 Amplify 并选择Amplify-Backend Deployment角色。接受所有默认值并为您的角色选择一个名称,例如AmplifyConsoleServiceRole-AmplifyRole
  5. 转到放大控制台
  6. 选择您的应用程序
  7. 转到右上角的“查看应用程序设置”
  8. 单击编辑
  9. 在服务角色下拉列表中 - 选择您刚刚创建的后端角色
  10. 保存并重新运行构建。

它应该有效。以下是供参考的 AWS 文档 - https://docs.aws.amazon.com/amplify/latest/userguide/how-to-service-role-amplify-console.html#step-3-return-to-the-amplify -安慰

  • 谢谢!这个解决方案有效。我很感谢您为提出如此好的答案而付出的努力。拯救了我的一天。 (2认同)