-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): automatically determine region on EC2 instances #9313
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4ab3429
Fix: allow EC2 instances to query IMDS to determine the region
joel-aws bb9fba6
Merge branch 'master' into joel-aws/instance-imds-region
joel-aws d0061ef
Cache isEc2Instance value and return it if available
joel-aws 9f8ffad
Properly signal failures in imds-related promises
joel-aws 0bcf8a6
Reformat and update semantics
joel-aws bfea5cf
Updated logging and handling of errors for IMDS calls
joel-aws 3e5bf4e
Merge branch 'master' into joel-aws/instance-imds-region
joel-aws 1f2b830
Fix missing semi error
joel-aws f1b364c
Catch potential json parsing errors
joel-aws 6113707
Removed isec2instance logging on grab from cache
joel-aws 835552b
replace let instead of var for isec2instancecache
joel-aws 5108dbf
Rewrite logic a little
rix0rrr e13ac15
Add mocked test
rix0rrr 815a4f7
Merge remote-tracking branch 'origin/master' into pr/joel-aws/9313
rix0rrr b624482
Merge remote-tracking branch 'origin/master' into pr/joel-aws/9313
rix0rrr fb46a7a
Merge branch 'master' into joel-aws/instance-imds-region
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as AWS from 'aws-sdk'; | ||
import { AwsCliCompatible } from '../../lib/api/aws-auth/awscli-compatible'; | ||
import { withMockedClassSingleton } from '../util'; | ||
|
||
beforeEach(() => { | ||
// Set to paths that don't exist so the SDK doesn't accidentally load this config | ||
process.env.AWS_CONFIG_FILE = '/home/dummydummy/.bxt/config'; | ||
process.env.AWS_SHARED_CREDENTIALS_FILE = '/home/dummydummy/.bxt/credentials'; | ||
// Scrub some environment variables that might be set if we're running on CodeBuild which will interfere with the tests. | ||
delete process.env.AWS_REGION; | ||
delete process.env.AWS_DEFAULT_REGION; | ||
delete process.env.AWS_ACCESS_KEY_ID; | ||
delete process.env.AWS_SECRET_ACCESS_KEY; | ||
delete process.env.AWS_SESSION_TOKEN; | ||
}); | ||
|
||
test('on an EC2 instance, region lookup queries IMDS', async () => { | ||
return withMockedClassSingleton(AWS, 'MetadataService', async (mdService) => { | ||
mdService.request | ||
// First call for a token | ||
.mockImplementationOnce((_1, _2, cb) => { cb(undefined as any, 'token'); }) | ||
// Second call for the region | ||
.mockImplementationOnce((_1, _2, cb) => { cb(undefined as any, JSON.stringify({ region: 'some-region' })); }); | ||
|
||
const region = await AwsCliCompatible.region({ ec2instance: true }); | ||
expect(region).toEqual('some-region'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: add an expectation that the mocks were actually called |
||
}); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding similar test cases for this method and its conditionals. Since this method already existed, I'll let you make the final call.