diff --git a/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt b/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt index c8629bbe8b..10e90ecbfc 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt +++ b/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt @@ -12,12 +12,6 @@ ################################################################################ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) - # Only enable AWS automated tests on Windows - set(SUPPORTED_PLATFORMS "Windows" "Linux") - if (NOT "${PAL_PLATFORM_NAME}" IN_LIST SUPPORTED_PLATFORMS) - return() - endif() - ly_add_pytest( NAME AutomatedTesting::AWSTests TEST_SUITE awsi diff --git a/AutomatedTesting/Gem/PythonTests/AWS/README.md b/AutomatedTesting/Gem/PythonTests/AWS/README.md index a25f39d9c2..73ef685261 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/README.md +++ b/AutomatedTesting/Gem/PythonTests/AWS/README.md @@ -3,7 +3,7 @@ ## Prerequisites 1. Build the O3DE Editor and AutomatedTesting.GameLauncher in Profile. 2. Install the latest version of NodeJs. -3. AWS CLI is installed and configured following [Configuration and Credential File Settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html). +3. AWS CLI is installed and AWS crendentials are configured via [environment variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) or [default profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html). 4. [AWS Cloud Development Kit (CDK)](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_install) is installed. ## Deploy CDK Applications diff --git a/AutomatedTesting/Gem/PythonTests/AWS/common/aws_credentials.py b/AutomatedTesting/Gem/PythonTests/AWS/common/aws_credentials.py index c6401f2828..d0bbfe7c3e 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/common/aws_credentials.py +++ b/AutomatedTesting/Gem/PythonTests/AWS/common/aws_credentials.py @@ -68,6 +68,10 @@ class AwsCredentials: if (len(self._credentials.sections()) == 0) and (not self._credentials_file_exists): os.remove(self._credentials_path) return + + credentials_file_dir = os.path.dirname(self._credentials_path) + if not os.path.isdir(credentials_file_dir): + os.makedirs(credentials_file_dir) with open(self._credentials_path, 'w+') as credential_file: self._credentials.write(credential_file) diff --git a/AutomatedTesting/Gem/PythonTests/AWS/common/aws_utils.py b/AutomatedTesting/Gem/PythonTests/AWS/common/aws_utils.py index 92f3762e71..2a5efbd03f 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/common/aws_utils.py +++ b/AutomatedTesting/Gem/PythonTests/AWS/common/aws_utils.py @@ -16,7 +16,7 @@ logging.getLogger('nose').setLevel(logging.WARNING) class AwsUtils: def __init__(self, arn: str, session_name: str, region_name: str): - local_session = boto3.Session(profile_name='default') + local_session = boto3.Session() local_sts_client = local_session.client('sts') self._local_account_id = local_sts_client.get_caller_identity()["Account"] logger.info(f'Local Account Id: {self._local_account_id}') diff --git a/AutomatedTesting/Gem/PythonTests/AWS/common/constants.py b/AutomatedTesting/Gem/PythonTests/AWS/common/constants.py index b12aca5f29..a38974073a 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/common/constants.py +++ b/AutomatedTesting/Gem/PythonTests/AWS/common/constants.py @@ -6,11 +6,13 @@ SPDX-License-Identifier: Apache-2.0 OR MIT """ import os +import platform # ARN of the IAM role to assume for retrieving temporary AWS credentials ASSUME_ROLE_ARN = os.environ.get('ASSUME_ROLE_ARN', 'arn:aws:iam::645075835648:role/o3de-automation-tests') # Name of the AWS project deployed by the CDK applications -AWS_PROJECT_NAME = os.environ.get('O3DE_AWS_PROJECT_NAME', 'AWSAUTO') +AWS_PROJECT_NAME = os.environ.get('O3DE_AWS_PROJECT_NAME').upper() if os.environ.get('O3DE_AWS_PROJECT_NAME') else \ + (os.environ.get('BRANCH_NAME', '') + '-' + os.environ.get('PIPELINE_NAME', '') + '-' + platform.system()).upper() # Region for the existing CloudFormation stacks used by the automation tests AWS_REGION = os.environ.get('O3DE_AWS_DEPLOY_REGION', 'us-east-1') # Name of the default resource mapping config file used by the automation tests diff --git a/scripts/build/Platform/Linux/build_config.json b/scripts/build/Platform/Linux/build_config.json index f61f91169a..c8f8752609 100644 --- a/scripts/build/Platform/Linux/build_config.json +++ b/scripts/build/Platform/Linux/build_config.json @@ -185,11 +185,11 @@ "COMMAND": "build_test_linux.sh", "PARAMETERS": { "CONFIGURATION": "profile", - "OUTPUT_DIRECTORY": "build\\linux", + "OUTPUT_DIRECTORY": "build/linux", "CMAKE_OPTIONS": "-G 'Ninja Multi-Config' -DLY_PARALLEL_LINK_JOBS=4", "CMAKE_LY_PROJECTS": "AutomatedTesting", "CMAKE_TARGET": "TEST_SUITE_awsi", - "CTEST_OPTIONS": "-L \"(SUITE_awsi)\" --no-tests=error", + "CTEST_OPTIONS": "-L (SUITE_awsi) --no-tests=error", "TEST_RESULTS": "True" } }, diff --git a/scripts/build/Platform/Linux/deploy_cdk_applications.sh b/scripts/build/Platform/Linux/deploy_cdk_applications.sh index 9a0a31397e..cccc796bdb 100755 --- a/scripts/build/Platform/Linux/deploy_cdk_applications.sh +++ b/scripts/build/Platform/Linux/deploy_cdk_applications.sh @@ -1,5 +1,5 @@ -#!/bin/bash - +#!/usr/bin/env bash +# # Copyright (c) Contributors to the Open 3D Engine Project. # For complete copyright and license terms please see the LICENSE at the root of this distribution. # @@ -8,7 +8,7 @@ # Deploy the CDK applications for AWS gems (Linux only) -SOURCE_DIRECTORY=$(dirname "$0") +SOURCE_DIRECTORY=$PWD PATH=$SOURCE_DIRECTORY/python:$PATH GEM_DIRECTORY=$SOURCE_DIRECTORY/Gems @@ -80,11 +80,14 @@ fi # Set temporary AWS credentials from the assume role credentials=$(aws sts assume-role --query Credentials.[SecretAccessKey,SessionToken,AccessKeyId] --output text --role-arn $ASSUME_ROLE_ARN --role-session-name o3de-Automation-session) -AWS_SECRET_ACCESS_KEY=$(echo "$credentials" | cut -d' ' -f1) -AWS_SESSION_TOKEN=$(echo "$credentials" | cut -d' ' -f2) -AWS_ACCESS_KEY_ID=$(echo "$credentials" | cut -d' ' -f3) +export AWS_SECRET_ACCESS_KEY=$(echo $credentials | cut -d' ' -f1) +export AWS_SESSION_TOKEN=$(echo $credentials | cut -d' ' -f2) +export AWS_ACCESS_KEY_ID=$(echo $credentials | cut -d' ' -f3) -O3DE_AWS_DEPLOY_ACCOUNT=$(echo "$ASSUME_ROLE_ARN" | cut -d':' -f5) +export O3DE_AWS_DEPLOY_ACCOUNT=$(echo "$ASSUME_ROLE_ARN" | cut -d':' -f5) +if [[ -z "$O3DE_AWS_PROJECT_NAME" ]]; then + export O3DE_AWS_PROJECT_NAME=$BRANCH_NAME-$PIPELINE_NAME-Linux +fi # Bootstrap and deploy the CDK applications echo [cdk_bootstrap] Bootstrap CDK diff --git a/scripts/build/Platform/Linux/destroy_cdk_applications.sh b/scripts/build/Platform/Linux/destroy_cdk_applications.sh index 54f84911a6..fd91e1a786 100755 --- a/scripts/build/Platform/Linux/destroy_cdk_applications.sh +++ b/scripts/build/Platform/Linux/destroy_cdk_applications.sh @@ -11,7 +11,7 @@ # 1) Node.js is installed # 2) Node.js version >= 10.13.0, except for versions 13.0.0 - 13.6.0. A version in active long-term support is recommended. -SOURCE_DIRECTORY=$(dirname "$0") +SOURCE_DIRECTORY=$PWD PATH=$SOURCE_DIRECTORY/python:$PATH GEM_DIRECTORY=$SOURCE_DIRECTORY/Gems @@ -70,12 +70,12 @@ echo [cdk_installation] Install the current version of nodejs nvm install node echo [cdk_installation] Install the latest version of CDK -if ! sudo npm uninstall -g aws-cdk; +if ! npm uninstall -g aws-cdk; then echo [cdk_bootstrap] Failed to uninstall the current version of CDK exit 1 fi -if ! sudo npm install -g aws-cdk@latest; +if ! npm install -g aws-cdk@latest; then echo [cdk_bootstrap] Failed to install the latest version of CDK exit 1 @@ -83,9 +83,13 @@ fi # Set temporary AWS credentials from the assume role credentials=$(aws sts assume-role --query Credentials.[SecretAccessKey,SessionToken,AccessKeyId] --output text --role-arn $ASSUME_ROLE_ARN --role-session-name o3de-Automation-session) -AWS_SECRET_ACCESS_KEY=$(echo "$credentials" | cut -d' ' -f1) -AWS_SESSION_TOKEN=$(echo "$credentials" | cut -d' ' -f2) -AWS_ACCESS_KEY_ID=$(echo "$credentials" | cut -d' ' -f3) +export AWS_SECRET_ACCESS_KEY=$(echo $credentials | cut -d' ' -f1) +export AWS_SESSION_TOKEN=$(echo $credentials | cut -d' ' -f2) +export AWS_ACCESS_KEY_ID=$(echo $credentials | cut -d' ' -f3) + +if [[ -z "$O3DE_AWS_PROJECT_NAME" ]]; then + export O3DE_AWS_PROJECT_NAME=$BRANCH_NAME-$PIPELINE_NAME-Linux +fi ERROR_EXISTS=0 DestroyCDKApplication AWSCore diff --git a/scripts/build/Platform/Linux/pipeline.json b/scripts/build/Platform/Linux/pipeline.json index e9667d312d..605adf1837 100644 --- a/scripts/build/Platform/Linux/pipeline.json +++ b/scripts/build/Platform/Linux/pipeline.json @@ -16,13 +16,6 @@ }, "PIPELINE_JENKINS_PARAMETERS": { "nightly-incremental": [ - { - "parameter_name": "O3DE_AWS_PROJECT_NAME", - "parameter_type": "string", - "default_value": "", - "use_last_run_value": true, - "description": "The name of the O3DE project that stacks should be deployed for." - }, { "parameter_name": "O3DE_AWS_DEPLOY_REGION", "parameter_type": "string", @@ -46,13 +39,6 @@ } ], "nightly-clean": [ - { - "parameter_name": "O3DE_AWS_PROJECT_NAME", - "parameter_type": "string", - "default_value": "", - "use_last_run_value": true, - "description": "The name of the O3DE project that stacks should be deployed for." - }, { "parameter_name": "O3DE_AWS_DEPLOY_REGION", "parameter_type": "string", diff --git a/scripts/build/Platform/Windows/deploy_cdk_applications.cmd b/scripts/build/Platform/Windows/deploy_cdk_applications.cmd index f3d68d2fe8..fca0835bd8 100644 --- a/scripts/build/Platform/Windows/deploy_cdk_applications.cmd +++ b/scripts/build/Platform/Windows/deploy_cdk_applications.cmd @@ -49,6 +49,10 @@ FOR /f "tokens=1,2,3" %%a IN ('CALL aws sts assume-role --query Credentials.[Sec ) FOR /F "tokens=4 delims=:" %%a IN ("%ASSUME_ROLE_ARN%") DO SET O3DE_AWS_DEPLOY_ACCOUNT=%%a +IF "%O3DE_AWS_PROJECT_NAME%"=="" ( + SET O3DE_AWS_PROJECT_NAME=%BRANCH_NAME%-%PIPELINE_NAME%-Windows +) + REM Bootstrap and deploy the CDK applications ECHO [cdk_bootstrap] Bootstrap CDK CALL cdk bootstrap aws://%O3DE_AWS_DEPLOY_ACCOUNT%/%O3DE_AWS_DEPLOY_REGION% diff --git a/scripts/build/Platform/Windows/destroy_cdk_applications.cmd b/scripts/build/Platform/Windows/destroy_cdk_applications.cmd index dacc9d327a..fe57619ff9 100644 --- a/scripts/build/Platform/Windows/destroy_cdk_applications.cmd +++ b/scripts/build/Platform/Windows/destroy_cdk_applications.cmd @@ -48,6 +48,9 @@ FOR /f "tokens=1,2,3" %%a IN ('CALL aws sts assume-role --query Credentials.[Sec SET AWS_ACCESS_KEY_ID=%%c ) FOR /F "tokens=4 delims=:" %%a IN ("%ASSUME_ROLE_ARN%") DO SET O3DE_AWS_DEPLOY_ACCOUNT=%%a +IF "%O3DE_AWS_PROJECT_NAME%"=="" ( + SET O3DE_AWS_PROJECT_NAME=%BRANCH_NAME%-%PIPELINE_NAME%-Windows +) SET ERROR_EXISTS=0 CALL :DestroyCDKApplication AWSCore,ERROR_EXISTS diff --git a/scripts/build/Platform/Windows/pipeline.json b/scripts/build/Platform/Windows/pipeline.json index 28d8437408..47e6af2d10 100644 --- a/scripts/build/Platform/Windows/pipeline.json +++ b/scripts/build/Platform/Windows/pipeline.json @@ -16,13 +16,6 @@ }, "PIPELINE_JENKINS_PARAMETERS": { "nightly-incremental": [ - { - "parameter_name": "O3DE_AWS_PROJECT_NAME", - "parameter_type": "string", - "default_value": "", - "use_last_run_value": true, - "description": "The name of the O3DE project that stacks should be deployed for." - }, { "parameter_name": "O3DE_AWS_DEPLOY_REGION", "parameter_type": "string", @@ -46,13 +39,6 @@ } ], "nightly-clean": [ - { - "parameter_name": "O3DE_AWS_PROJECT_NAME", - "parameter_type": "string", - "default_value": "", - "use_last_run_value": true, - "description": "The name of the O3DE project that stacks should be deployed for." - }, { "parameter_name": "O3DE_AWS_DEPLOY_REGION", "parameter_type": "string",