我正在尝试获取用 .NET 8 编写并在 Docker Compose 3 上运行的服务,以便在与 AWS 服务(在本例中为 SQS)通信时使用我的 AWS SSO 凭证。
我的 AWS
config
文件定义为:
[default]
region = ap-southeast-2
[sso-session lets-go]
sso_start_url=https://my-org-entrypoint.awsapps.com/start
sso_region=ap-southeast-2
sso_registration_scopes=sso:account:access
[profile non-prod]
sso_session=lets-go
sso_account_id=xxxxxxxxxxxx
sso_role_name=DeveloperAccess
我的
docker-compose.yml
是
name: 'my-product'
services:
my-service:
build:
dockerfile: src/my-app/Dockerfile
environment:
- DOTNET_ENVIRONMENT=Development
- AWS_PROFILE=non-prod
- AWS_REGION=ap-southeast-2
- AWS_CONFIG_FILE=/app/.aws/config
- AWS_SSO_SESSION=lets-go
volumes:
- ~/.aws:/app/.aws:ro
我将
.aws
文件夹安装到 /app
而不是 /root
,因为我的 Docker 映像以非 root 用户身份运行,但我尝试将其安装到 /root
以防万一,但没有成功。
我通过 SSO 登录,然后启动应用程序:
aws sso login --profile non-prod
docker compose up -d
容器启动,我在其日志中看到以下内容:
[23:49:43 INF] Initiating startup
[23:49:43 INF] Found credentials using the AWS SDK's default credential search
[23:49:45 ERR] Error while initialising queue
Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at OpenTelemetry.Instrumentation.AWS.Implementation.AWSPropagatorPipelineHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at OpenTelemetry.Instrumentation.AWS.Implementation.AWSTracingPipelineHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
如果我进入 Docker Desktop 并浏览容器,我可以看到
.aws
文件夹中的所有文件都已正确安装在预期位置。
知道我做错了什么吗?
我认为我们正在尝试做同样的事情 David,您能在容器中看到 .aws 文件夹吗?