-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Added Support for Test Account Management #3845
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
34054b5
Added get_testing_resources.py
CoshUS 08a5375
Added Setting Test Env Vars
CoshUS c16ad41
Added send-task-success to Windows
CoshUS decf01b
Updated MANAGED_TEST_RESOURCE_STACK_NAME
CoshUS f494c2d
Fixed Region and Bash Env Var
CoshUS 347e1d6
Added venv to get_testing_resources
CoshUS e3909b2
Fixed CredentialDistributionLambda region
CoshUS 214f1c0
Added Cred Protection for Testing
CoshUS 28f1189
Fixed Python Version
CoshUS f132d5a
Added venv for pythonn3.9
CoshUS ef51f98
Fixed FunctionError Check
CoshUS 835d673
Fixed Cred Key Names
CoshUS c46a368
Fixed jq echo Syntax
CoshUS 1d9e71a
Removed test_env_var Debug Echo
CoshUS 91c983c
Added Docker Authentication and Cred Swap
CoshUS 0095df7
Merge branch 'develop' of https://github.com/aws/aws-sam-cli into fea…
CoshUS 7359b4a
Added Debug STS Caller Identity
CoshUS e06d0d7
Removed Debug STS
CoshUS e50b56a
Updated Lambda Max Attempts to Avoid Calling Multiple Times
CoshUS c9c8899
Fixed Ubuntu NoAvailableAccountException Check
CoshUS d114fcb
Added Exit to NoAvailableAccountException
CoshUS c6c7312
Updated to Exit Code Check
CoshUS 6becea3
Fixed Ubuntu jq and Windows Newlines
CoshUS c94e462
Fixed Windows on_finish Newlines
CoshUS f0ac65a
Removed Docker for Non Canary CI
CoshUS a9220a2
Updated to Echo Static Error Message
CoshUS d13ebf2
Added Docs for get_testing_resources
CoshUS 6739d90
Merge branch 'develop' into feat/test-account-management-support
mndeveci 36f3e28
Fixed Ubuntu Send TaskToken
CoshUS a6c0e72
Merge branch 'feat/test-account-management-support' of https://github…
CoshUS 3e94ab7
Merge branch 'develop' into feat/test-account-management-support
qingchm 7364153
Merge branch 'develop' into feat/test-account-management-support
mndeveci b24b7b9
Merge branch 'develop' into feat/test-account-management-support
mndeveci 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| """ | ||
| Script for getting test account credentials and managed test account resources. | ||
| The output will be a json string with creds and resource names. | ||
| """ | ||
| import json | ||
| import os | ||
|
|
||
| import boto3 | ||
| from boto3.session import Session | ||
| from botocore.config import Config | ||
|
|
||
| DEFAULT_BOTO_CONFIG = Config(retries={"max_attempts": 10, "mode": "standard"}) | ||
| MANAGED_TEST_RESOURCE_STACK_NAME = "managed-test-resources" | ||
| LAMBDA_TIME_OUT = 300 | ||
|
|
||
|
|
||
| def main(): | ||
| env_vars = get_testing_credentials() | ||
| # Assume testing account credential in order to access managed test resource stack | ||
| test_session = Session( | ||
| aws_access_key_id=env_vars["accessKeyID"], | ||
| aws_secret_access_key=env_vars["secretAccessKey"], | ||
| aws_session_token=env_vars["sessionToken"], | ||
| ) | ||
| env_vars.update(get_managed_test_resource_outputs(test_session)) | ||
| print(json.dumps(env_vars)) | ||
|
|
||
|
|
||
| def get_managed_test_resource_outputs(session: Session): | ||
| """Read output of the managed test resource stack for resource names and arns""" | ||
| cfn_resource = session.resource("cloudformation", config=DEFAULT_BOTO_CONFIG, region_name="us-east-1") | ||
| stack = cfn_resource.Stack(MANAGED_TEST_RESOURCE_STACK_NAME) | ||
| outputs_dict = dict() | ||
| for output in stack.outputs: | ||
| outputs_dict[output["OutputKey"]] = output["OutputValue"] | ||
| return outputs_dict | ||
|
|
||
|
|
||
| def get_testing_credentials(): | ||
| lambda_arn = os.environ["CREDENTIAL_DISTRIBUTION_LAMBDA_ARN"] | ||
| # Max attempts to 0 so that boto3 will not invoke multiple times | ||
| lambda_client = boto3.client( | ||
| "lambda", | ||
| config=Config( | ||
| retries={"max_attempts": 0, "mode": "standard"}, | ||
| connect_timeout=LAMBDA_TIME_OUT + 60, | ||
| read_timeout=LAMBDA_TIME_OUT + 60, | ||
| ), | ||
| region_name="us-west-2", | ||
| ) | ||
| response = lambda_client.invoke(FunctionName=lambda_arn) | ||
| payload = json.loads(response["Payload"].read()) | ||
| if response.get("FunctionError"): | ||
| raise ValueError(f"Failed to get credential. {payload['errorType']}") | ||
| return payload | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.