Skip to content

Conversation

@ducks
Copy link
Contributor

@ducks ducks commented Aug 21, 2025

Implement missing credential_source = Environment support in Ruby SDK

Problem

The AWS CLI documentation clearly states that credential_source supports three values:

  • Environment – Specifies that the AWS CLI is to retrieve source credentials from environment variables
  • Ec2InstanceMetadata – Specifies that the AWS CLI is to use the IAM role attached to the EC2 instance profile
  • EcsContainer – Specifies that the AWS CLI is to use the IAM role attached to the ECS container

However, the Ruby SDK only implemented the latter two, causing InvalidCredentialSourceError when users try to use the documented Environment option.

Solution

This adds the missing Environment case in SharedConfig#credentials_from_source that retrieves credentials from:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_SESSION_TOKEN

This matches the documented AWS CLI behavior.

Testing

  • Added comprehensive test coverage for the new Environment credential source
  • All existing gems tests pass (19620 examples, 0 failures)
  • Verified no regressions across AWS SDK ecosystem

Impact

Fixes a gap where documented AWS credential functionality throws InvalidCredentialSourceError in the Ruby SDK.

- Implements missing Environment credential source documented in AWS CLI docs
- Returns Credentials object using AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
- Includes comprehensive test coverage
- All existing tests pass (2315 examples, 0 failures)
@jterapin
Copy link
Contributor

Hi! Thank you for your contribution. I will be taking a look.

@richardwang1124
Copy link
Contributor

Hey, thanks for opening a PR. I agree that we should support this and I may make some changes to this PR as well.

@ducks
Copy link
Contributor Author

ducks commented Aug 22, 2025

cool cool. thanks. I'm open to any feedback/help. seemed like too simple a fix but those are the best kinds I guess.

Copy link
Contributor

@jterapin jterapin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks y'all.

@richardwang1124 richardwang1124 merged commit 9c7fd0f into aws:version-3 Aug 25, 2025
24 checks passed
@ducks
Copy link
Contributor Author

ducks commented Aug 26, 2025

wow, thanks to y'all as well for helping me get this merged in so fast.

One question I had was on this comment:

I actually think we don't need to bump s3 min core since this credential_source usage only applies within Amazon EC2 instances or Amazon Elastic Container Service containers

I am trying to use this on a self-hosted, non ec2 metal server and was seeing the same error when trying to use credential_source = Environment.

I see the other 2 options for the case are for ec2 instances but it seems like this should work elsewhere fwict.

@richardwang1124
Copy link
Contributor

You're correct, credential_source = Environment is not specific to EC2/ECS, it should work everywhere. Thanks again for your contribution! The changes should be going out as part of today's release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants