gpt4 book ai didi

java - 使用 AWS SSO 时 AWS Java SDK 找不到配置文件

转载 作者:行者123 更新时间:2023-12-04 11:29:01 25 4
gpt4 key购买 nike

当我使用 AWS SSO 登录时,我无法访问 aws。
我从我的电脑登录使用:

aws sso login --profile staging
配置文件配置如下:
[profile staging]
sso_start_url = https://som-nice-working-url
sso_region = us-east-1
sso_account_id = 1234
sso_role_name = the-role-name
region = eu-west-1
output = yaml
登录后,我可以通过 aws cli 访问 aws。
然后我设置变量: AWS_PROFILE=staging但是在 Java 上,我收到以下异常:
com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), WebIdentityTokenCredentialsProvider: You must specify a value for roleArn and roleSessionName, com.amazonaws.auth.profile.ProfileCredentialsProvider@369a95a5: No AWS profile named 'staging', com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@6d6f6ca9: Failed to connect to service endpoint: ]
我已经尝试将 ProfileCredentialsProvider 与“暂存”一起使用,但结果是一样的。
什么 CredentialsProvider我应该使用吗?
我的代码正在使用 DefaultProviderChain:
AWSGlueClient.builder()
.withRegion("eu-west-1")
.build()
谢谢你。

最佳答案

对于 Java 应用程序,您需要 SSO Dependency .
截至撰写本文时,最新版本是 2.16.76

// Gradle example
dependencies {

implementation(platform("software.amazon.awssdk:bom:2.16.70"))
implementation("software.amazon.awssdk:sso:2.16.76")
}
您还需要设置 default个人资料 ~/.aws/configuration~/.aws/credentials更多信息如下:
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup.html#setup-credentials
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup-additional.html#setup-additional-credentials
但是,您也应该能够设置 AWS_PROFILE环境变量添加到您的配置文件中,它也应该在没有 SSO 依赖的情况下神奇地工作。
在您的示例中,具体来说:
AWS_PROFILE=staging

关于java - 使用 AWS SSO 时 AWS Java SDK 找不到配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64062720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com