gor*_*oro 7 java sdk amazon-web-services single-sign-on
当我使用 AWS SSO 登录时,我无法访问 aws。我从我的电脑登录使用:
aws sso login --profile staging
Run Code Online (Sandbox Code Playgroud)
配置文件配置如下:
[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
Run Code Online (Sandbox Code Playgroud)
登录后,我可以通过 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: ]
Run Code Online (Sandbox Code Playgroud)
我已经尝试将 ProfileCredentialsProvider 与“暂存”一起使用,但结果是一样的。
我CredentialsProvider应该使用什么?
我的代码正在使用 DefaultProviderChain:
AWSGlueClient.builder()
.withRegion("eu-west-1")
.build()
Run Code Online (Sandbox Code Playgroud)
谢谢你。
Arc*_*ede 20
对于 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")
}
Run Code Online (Sandbox Code Playgroud)
您还需要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
Run Code Online (Sandbox Code Playgroud)
就我而言,只需添加 aws-sso 依赖项:
\n <dependency>\n <groupId>software.amazon.awssdk</groupId>\n <artifactId>sso</artifactId>\n </dependency>\nRun Code Online (Sandbox Code Playgroud)\n允许默认凭据提供程序链在以下位置获取 sso ProfileCredentialsProvider:\n
要开箱即用,您需要指定[default]配置文件。否则,简单地使用.credentialsProvider(ProfileCredentialsProvider.create("xyz"))也适用于[profile xyz].
如果全部失败,请手动添加凭据提供程序:
\n.aws/configaws sso login --profile <your_profile>.aws/sso/cache其内容如下所述 <dependency>\n <groupId>software.amazon.awssdk</groupId>\n <artifactId>sso</artifactId>\n </dependency>\nRun Code Online (Sandbox Code Playgroud)\nsoftware.amazon.awssdk:ssoSsoCredentialsProvider使用 json 文件中的数据创建:{\n "startUrl": "https://my-sso-portal.awsapps.com/start",\n "region": "us-east-1",\n "accessToken": "eyJlbmMiOiJBM\xe2\x80\xa6.",\n "expiresAt": "2020-06-17T10:02:08UTC"\n}\nRun Code Online (Sandbox Code Playgroud)\n
我可能是错的,但在我看来,目前还无法基于https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html在 AWS SDK 中使用 AWS SSO 。
据我所知,AWS SSO 目前仅集成到 AWS CLI 中 - https://docs.aws.amazon.com/singlesignon/latest/userguide/integrating-aws-cli.html
| 归档时间: |
|
| 查看次数: |
1420 次 |
| 最近记录: |