diff --git a/run-sdk.sh b/run-sdk.sh new file mode 100755 index 00000000..575d986b --- /dev/null +++ b/run-sdk.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Shared SDK runner — sourced by each tutorial's *-sdk.sh script. +set -eo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)" +LANG="${1:-}" +usage() { + echo "Usage: $(basename "${BASH_SOURCE[1]}") " + echo " python|py, javascript|js, java, go, ruby|rb, dotnet|cs, rust|rs, kotlin|kt, swift, php, cpp" + echo "" + echo "Available:" + for d in "$SCRIPT_DIR"/*/; do [ -d "$d" ] && basename "$d" | grep -qvE '^\.' && echo " $(basename "$d")"; done + exit 1 +} +[ -z "$LANG" ] && usage +case "$LANG" in + python|py) DIR="python" ;; javascript|js|node) DIR="javascript" ;; java) DIR="java" ;; + go|golang) DIR="go" ;; ruby|rb) DIR="ruby" ;; dotnet|csharp|cs) DIR="dotnet" ;; + rust|rs) DIR="rust" ;; kotlin|kt) DIR="kotlin" ;; swift) DIR="swift" ;; + php) DIR="php" ;; cpp|c++) DIR="cpp" ;; *) echo "Unknown: $LANG"; usage ;; +esac +LANG_DIR="$SCRIPT_DIR/$DIR" +[ ! -d "$LANG_DIR" ] && echo "No $DIR example for this tutorial." && usage +check_cmd() { command -v "$1" > /dev/null 2>&1 || { echo "Required: $1 not installed. Install: $2"; exit 1; }; } +case "$DIR" in + python) check_cmd python3 "https://python.org/downloads/"; cd "$LANG_DIR" + [ ! -d ".venv" ] && python3 -m venv .venv; source .venv/bin/activate; pip install -q -r requirements.txt + echo "$ python3 scenario_getting_started.py"; echo ""; python3 scenario_getting_started.py ;; + javascript) check_cmd node "https://nodejs.org/"; cd "$LANG_DIR" + [ ! -d "node_modules" ] && npm install --quiet + echo "$ node scenarios/getting-started.js"; echo ""; node scenarios/getting-started.js ;; + java) check_cmd mvn "https://maven.apache.org/install.html"; cd "$LANG_DIR" + echo "$ mvn -q compile exec:java"; mvn -q compile exec:java 2>&1 ;; + go) check_cmd go "https://go.dev/dl/"; cd "$LANG_DIR" + echo "$ go run scenarios/getting_started.go"; echo ""; go run scenarios/getting_started.go ;; + ruby) check_cmd ruby "https://ruby-lang.org/"; cd "$LANG_DIR" + [ ! -f "Gemfile.lock" ] && bundle install --quiet + echo "$ ruby scenario_getting_started.rb"; echo ""; ruby scenario_getting_started.rb ;; + dotnet) check_cmd dotnet "https://dotnet.microsoft.com/download"; cd "$LANG_DIR" + echo "$ dotnet run"; echo ""; dotnet run ;; + rust) check_cmd cargo "https://rustup.rs/"; cd "$LANG_DIR" + echo "$ cargo run --bin scenario"; echo ""; cargo run --bin scenario ;; + kotlin) check_cmd java "https://aws.amazon.com/corretto/"; cd "$LANG_DIR" + echo "$ ./gradlew run"; chmod +x gradlew 2>/dev/null; ./gradlew run --quiet ;; + swift) check_cmd swift "https://swift.org/download/"; cd "$LANG_DIR" + echo "$ swift run"; echo ""; swift run ;; + php) check_cmd php "https://php.net/downloads"; cd "$LANG_DIR" + [ ! -d "vendor" ] && composer install --quiet + echo "$ php GettingStartedScenario.php"; echo ""; php GettingStartedScenario.php ;; + cpp) check_cmd cmake "https://cmake.org/download/"; cd "$LANG_DIR" + mkdir -p build && cd build; echo "$ cmake .. && make && ./scenario" + cmake .. -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1; make -j > /dev/null 2>&1 && ./scenario ;; +esac diff --git a/tuts/001-lightsail-gs/lightsail-gs-sdk.sh b/tuts/001-lightsail-gs/lightsail-gs-sdk.sh new file mode 100755 index 00000000..c188f0c2 --- /dev/null +++ b/tuts/001-lightsail-gs/lightsail-gs-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash lightsail-gs-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/001-lightsail-gs/python/lightsail_wrapper.py b/tuts/001-lightsail-gs/python/lightsail_wrapper.py new file mode 100644 index 00000000..e8288166 --- /dev/null +++ b/tuts/001-lightsail-gs/python/lightsail_wrapper.py @@ -0,0 +1,58 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class LightsailWrapper: + def __init__(self, client): + self.client = client + + def create_instances(self, instance_name, blueprint_id='amazon_linux_2023', bundle_id='nano_3_2'): + """Calls lightsail:CreateInstances.""" + try: + self.client.create_instances(instanceNames=[instance_name], blueprintId=blueprint_id, bundleId=bundle_id, availabilityZone=f'{self.client.meta.region_name}a') + logger.info("CreateInstances succeeded.") + except ClientError: + logger.exception("CreateInstances failed.") + raise + + def create_disk(self, disk_name, size_in_gb=8): + """Calls lightsail:CreateDisk.""" + try: + self.client.create_disk(diskName=disk_name, sizeInGb=size_in_gb, availabilityZone=f'{self.client.meta.region_name}a') + logger.info("CreateDisk succeeded.") + except ClientError: + logger.exception("CreateDisk failed.") + raise + + def get_instance(self, instance_name): + """Calls lightsail:GetInstance.""" + try: + return self.client.get_instance(instanceName=instance_name)['instance'] + logger.info("GetInstance succeeded.") + except ClientError: + logger.exception("GetInstance failed.") + raise + + def delete_instance(self, instance_name): + """Calls lightsail:DeleteInstance.""" + try: + self.client.delete_instance(instanceName=instance_name) + logger.info("DeleteInstance succeeded.") + except ClientError: + logger.exception("DeleteInstance failed.") + raise + + def delete_disk(self, disk_name): + """Calls lightsail:DeleteDisk.""" + try: + self.client.delete_disk(diskName=disk_name) + logger.info("DeleteDisk succeeded.") + except ClientError: + logger.exception("DeleteDisk failed.") + raise diff --git a/tuts/001-lightsail-gs/python/requirements.txt b/tuts/001-lightsail-gs/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/001-lightsail-gs/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/001-lightsail-gs/python/scenario_getting_started.py b/tuts/001-lightsail-gs/python/scenario_getting_started.py new file mode 100644 index 00000000..ebd1629d --- /dev/null +++ b/tuts/001-lightsail-gs/python/scenario_getting_started.py @@ -0,0 +1,19 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from lightsail_wrapper import LightsailWrapper + + +def run_scenario(): + client = boto3.client("lightsail") + wrapper = LightsailWrapper(client) + suffix = uuid.uuid4().hex[:8] + print(f"Running Lightsail getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/001-lightsail-gs/python/test_lightsail.py b/tuts/001-lightsail-gs/python/test_lightsail.py new file mode 100644 index 00000000..47b478a9 --- /dev/null +++ b/tuts/001-lightsail-gs/python/test_lightsail.py @@ -0,0 +1,21 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from lightsail_wrapper import LightsailWrapper + + +@pytest.fixture +def lightsail_stubber(): + client = boto3.client("lightsail", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(capsys, lightsail_stubber): + client, stubber = lightsail_stubber + wrapper = LightsailWrapper(client) + # TODO: add stubbed responses and assertions + assert wrapper is not None diff --git a/tuts/002-vpc-gs/python/ec2_wrapper.py b/tuts/002-vpc-gs/python/ec2_wrapper.py new file mode 100644 index 00000000..ad303962 --- /dev/null +++ b/tuts/002-vpc-gs/python/ec2_wrapper.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class EC2Wrapper: + def __init__(self, client): + self.client = client + + # TODO: Add wrapper methods matching the CLI tutorial actions diff --git a/tuts/002-vpc-gs/python/requirements.txt b/tuts/002-vpc-gs/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/002-vpc-gs/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/002-vpc-gs/python/scenario_getting_started.py b/tuts/002-vpc-gs/python/scenario_getting_started.py new file mode 100644 index 00000000..bed6de1a --- /dev/null +++ b/tuts/002-vpc-gs/python/scenario_getting_started.py @@ -0,0 +1,18 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from ec2_wrapper import EC2Wrapper + + +def run_scenario(): + client = boto3.client("ec2") + wrapper = EC2Wrapper(client) + print(f"Running EC2 getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/002-vpc-gs/python/test_ec2.py b/tuts/002-vpc-gs/python/test_ec2.py new file mode 100644 index 00000000..724f39e3 --- /dev/null +++ b/tuts/002-vpc-gs/python/test_ec2.py @@ -0,0 +1,20 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from ec2_wrapper import EC2Wrapper + + +@pytest.fixture +def stubber(): + client = boto3.client("ec2", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(stubber): + client, stub = stubber + wrapper = EC2Wrapper(client) + assert wrapper is not None diff --git a/tuts/002-vpc-gs/vpc-gs-sdk.sh b/tuts/002-vpc-gs/vpc-gs-sdk.sh new file mode 100755 index 00000000..f2622fd7 --- /dev/null +++ b/tuts/002-vpc-gs/vpc-gs-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash vpc-gs-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/003-s3-gettingstarted/python/requirements.txt b/tuts/003-s3-gettingstarted/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/003-s3-gettingstarted/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/003-s3-gettingstarted/python/s3_wrapper.py b/tuts/003-s3-gettingstarted/python/s3_wrapper.py new file mode 100644 index 00000000..00adde58 --- /dev/null +++ b/tuts/003-s3-gettingstarted/python/s3_wrapper.py @@ -0,0 +1,76 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class S3Wrapper: + def __init__(self, client): + self.client = client + + def create_bucket(self, bucket_name): + """Calls s3:CreateBucket.""" + try: + self.client.create_bucket(Bucket=bucket_name) + logger.info("CreateBucket succeeded.") + except ClientError: + logger.exception("CreateBucket failed.") + raise + + def put_object(self, bucket_name, key, body): + """Calls s3:PutObject.""" + try: + self.client.put_object(Bucket=bucket_name, Key=key, Body=body) + logger.info("PutObject succeeded.") + except ClientError: + logger.exception("PutObject failed.") + raise + + def get_object(self, bucket_name, key): + """Calls s3:GetObject.""" + try: + return self.client.get_object(Bucket=bucket_name, Key=key)['Body'].read() + logger.info("GetObject succeeded.") + except ClientError: + logger.exception("GetObject failed.") + raise + + def copy_object(self, src_bucket, src_key, dst_bucket, dst_key): + """Calls s3:CopyObject.""" + try: + self.client.copy_object(CopySource={'Bucket': src_bucket, 'Key': src_key}, Bucket=dst_bucket, Key=dst_key) + logger.info("CopyObject succeeded.") + except ClientError: + logger.exception("CopyObject failed.") + raise + + def list_objects(self, bucket_name): + """Calls s3:ListObjectsV2.""" + try: + return self.client.list_objects_v2(Bucket=bucket_name).get('Contents', []) + logger.info("ListObjectsV2 succeeded.") + except ClientError: + logger.exception("ListObjectsV2 failed.") + raise + + def delete_objects(self, bucket_name, keys): + """Calls s3:DeleteObjects.""" + try: + self.client.delete_objects(Bucket=bucket_name, Delete={'Objects': [{'Key': k} for k in keys]}) + logger.info("DeleteObjects succeeded.") + except ClientError: + logger.exception("DeleteObjects failed.") + raise + + def delete_bucket(self, bucket_name): + """Calls s3:DeleteBucket.""" + try: + self.client.delete_bucket(Bucket=bucket_name) + logger.info("DeleteBucket succeeded.") + except ClientError: + logger.exception("DeleteBucket failed.") + raise diff --git a/tuts/003-s3-gettingstarted/python/scenario_getting_started.py b/tuts/003-s3-gettingstarted/python/scenario_getting_started.py new file mode 100644 index 00000000..758124ed --- /dev/null +++ b/tuts/003-s3-gettingstarted/python/scenario_getting_started.py @@ -0,0 +1,19 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from s3_wrapper import S3Wrapper + + +def run_scenario(): + client = boto3.client("s3") + wrapper = S3Wrapper(client) + suffix = uuid.uuid4().hex[:8] + print(f"Running S3 getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/003-s3-gettingstarted/python/test_s3.py b/tuts/003-s3-gettingstarted/python/test_s3.py new file mode 100644 index 00000000..f2d5e8c2 --- /dev/null +++ b/tuts/003-s3-gettingstarted/python/test_s3.py @@ -0,0 +1,21 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from s3_wrapper import S3Wrapper + + +@pytest.fixture +def s3_stubber(): + client = boto3.client("s3", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(capsys, s3_stubber): + client, stubber = s3_stubber + wrapper = S3Wrapper(client) + # TODO: add stubbed responses and assertions + assert wrapper is not None diff --git a/tuts/003-s3-gettingstarted/s3-gettingstarted-sdk.sh b/tuts/003-s3-gettingstarted/s3-gettingstarted-sdk.sh new file mode 100755 index 00000000..6ff04a84 --- /dev/null +++ b/tuts/003-s3-gettingstarted/s3-gettingstarted-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash s3-gettingstarted-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/004-cloudmap-custom-attributes/cloudmap-custom-attributes-sdk.sh b/tuts/004-cloudmap-custom-attributes/cloudmap-custom-attributes-sdk.sh new file mode 100755 index 00000000..b8a18d91 --- /dev/null +++ b/tuts/004-cloudmap-custom-attributes/cloudmap-custom-attributes-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash cloudmap-custom-attributes-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/004-cloudmap-custom-attributes/python/requirements.txt b/tuts/004-cloudmap-custom-attributes/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/004-cloudmap-custom-attributes/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/004-cloudmap-custom-attributes/python/scenario_getting_started.py b/tuts/004-cloudmap-custom-attributes/python/scenario_getting_started.py new file mode 100644 index 00000000..b1837c21 --- /dev/null +++ b/tuts/004-cloudmap-custom-attributes/python/scenario_getting_started.py @@ -0,0 +1,18 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from servicediscovery_wrapper import CloudMapAttrsWrapper + + +def run_scenario(): + client = boto3.client("servicediscovery") + wrapper = CloudMapAttrsWrapper(client) + print(f"Running CloudMapAttrs getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/004-cloudmap-custom-attributes/python/servicediscovery_wrapper.py b/tuts/004-cloudmap-custom-attributes/python/servicediscovery_wrapper.py new file mode 100644 index 00000000..0f3922e5 --- /dev/null +++ b/tuts/004-cloudmap-custom-attributes/python/servicediscovery_wrapper.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class CloudMapAttrsWrapper: + def __init__(self, client): + self.client = client + + # TODO: Add wrapper methods matching the CLI tutorial actions diff --git a/tuts/004-cloudmap-custom-attributes/python/test_servicediscovery.py b/tuts/004-cloudmap-custom-attributes/python/test_servicediscovery.py new file mode 100644 index 00000000..bd231c2e --- /dev/null +++ b/tuts/004-cloudmap-custom-attributes/python/test_servicediscovery.py @@ -0,0 +1,20 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from servicediscovery_wrapper import CloudMapAttrsWrapper + + +@pytest.fixture +def stubber(): + client = boto3.client("servicediscovery", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(stubber): + client, stub = stubber + wrapper = CloudMapAttrsWrapper(client) + assert wrapper is not None diff --git a/tuts/005-cloudfront-gettingstarted/cloudfront-gettingstarted-sdk.sh b/tuts/005-cloudfront-gettingstarted/cloudfront-gettingstarted-sdk.sh new file mode 100755 index 00000000..13452476 --- /dev/null +++ b/tuts/005-cloudfront-gettingstarted/cloudfront-gettingstarted-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash cloudfront-gettingstarted-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/005-cloudfront-gettingstarted/python/cloudfront_wrapper.py b/tuts/005-cloudfront-gettingstarted/python/cloudfront_wrapper.py new file mode 100644 index 00000000..167e00a0 --- /dev/null +++ b/tuts/005-cloudfront-gettingstarted/python/cloudfront_wrapper.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class CloudFrontWrapper: + def __init__(self, client): + self.client = client + + # TODO: Add wrapper methods matching the CLI tutorial actions diff --git a/tuts/005-cloudfront-gettingstarted/python/requirements.txt b/tuts/005-cloudfront-gettingstarted/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/005-cloudfront-gettingstarted/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/005-cloudfront-gettingstarted/python/scenario_getting_started.py b/tuts/005-cloudfront-gettingstarted/python/scenario_getting_started.py new file mode 100644 index 00000000..915f3539 --- /dev/null +++ b/tuts/005-cloudfront-gettingstarted/python/scenario_getting_started.py @@ -0,0 +1,18 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from cloudfront_wrapper import CloudFrontWrapper + + +def run_scenario(): + client = boto3.client("cloudfront") + wrapper = CloudFrontWrapper(client) + print(f"Running CloudFront getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/005-cloudfront-gettingstarted/python/test_cloudfront.py b/tuts/005-cloudfront-gettingstarted/python/test_cloudfront.py new file mode 100644 index 00000000..f799b61c --- /dev/null +++ b/tuts/005-cloudfront-gettingstarted/python/test_cloudfront.py @@ -0,0 +1,20 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from cloudfront_wrapper import CloudFrontWrapper + + +@pytest.fixture +def stubber(): + client = boto3.client("cloudfront", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(stubber): + client, stub = stubber + wrapper = CloudFrontWrapper(client) + assert wrapper is not None diff --git a/tuts/008-vpc-private-servers-gs/python/ec2_wrapper.py b/tuts/008-vpc-private-servers-gs/python/ec2_wrapper.py new file mode 100644 index 00000000..58a4c557 --- /dev/null +++ b/tuts/008-vpc-private-servers-gs/python/ec2_wrapper.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class VPCPrivateWrapper: + def __init__(self, client): + self.client = client + + # TODO: Add wrapper methods matching the CLI tutorial actions diff --git a/tuts/008-vpc-private-servers-gs/python/requirements.txt b/tuts/008-vpc-private-servers-gs/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/008-vpc-private-servers-gs/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/008-vpc-private-servers-gs/python/scenario_getting_started.py b/tuts/008-vpc-private-servers-gs/python/scenario_getting_started.py new file mode 100644 index 00000000..c05b297b --- /dev/null +++ b/tuts/008-vpc-private-servers-gs/python/scenario_getting_started.py @@ -0,0 +1,18 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from ec2_wrapper import VPCPrivateWrapper + + +def run_scenario(): + client = boto3.client("ec2") + wrapper = VPCPrivateWrapper(client) + print(f"Running VPCPrivate getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/008-vpc-private-servers-gs/python/test_ec2.py b/tuts/008-vpc-private-servers-gs/python/test_ec2.py new file mode 100644 index 00000000..52ee3026 --- /dev/null +++ b/tuts/008-vpc-private-servers-gs/python/test_ec2.py @@ -0,0 +1,20 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from ec2_wrapper import VPCPrivateWrapper + + +@pytest.fixture +def stubber(): + client = boto3.client("ec2", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(stubber): + client, stub = stubber + wrapper = VPCPrivateWrapper(client) + assert wrapper is not None diff --git a/tuts/008-vpc-private-servers-gs/vpc-private-servers-gs-sdk.sh b/tuts/008-vpc-private-servers-gs/vpc-private-servers-gs-sdk.sh new file mode 100755 index 00000000..ae5cb525 --- /dev/null +++ b/tuts/008-vpc-private-servers-gs/vpc-private-servers-gs-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash vpc-private-servers-gs-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/009-vpc-ipam-gs/python/ec2_wrapper.py b/tuts/009-vpc-ipam-gs/python/ec2_wrapper.py new file mode 100644 index 00000000..f4402db8 --- /dev/null +++ b/tuts/009-vpc-ipam-gs/python/ec2_wrapper.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class IPAMWrapper: + def __init__(self, client): + self.client = client + + # TODO: Add wrapper methods matching the CLI tutorial actions diff --git a/tuts/009-vpc-ipam-gs/python/requirements.txt b/tuts/009-vpc-ipam-gs/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/009-vpc-ipam-gs/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/009-vpc-ipam-gs/python/scenario_getting_started.py b/tuts/009-vpc-ipam-gs/python/scenario_getting_started.py new file mode 100644 index 00000000..fc159229 --- /dev/null +++ b/tuts/009-vpc-ipam-gs/python/scenario_getting_started.py @@ -0,0 +1,18 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from ec2_wrapper import IPAMWrapper + + +def run_scenario(): + client = boto3.client("ec2") + wrapper = IPAMWrapper(client) + print(f"Running IPAM getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/009-vpc-ipam-gs/python/test_ec2.py b/tuts/009-vpc-ipam-gs/python/test_ec2.py new file mode 100644 index 00000000..4cc8d6eb --- /dev/null +++ b/tuts/009-vpc-ipam-gs/python/test_ec2.py @@ -0,0 +1,20 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from ec2_wrapper import IPAMWrapper + + +@pytest.fixture +def stubber(): + client = boto3.client("ec2", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(stubber): + client, stub = stubber + wrapper = IPAMWrapper(client) + assert wrapper is not None diff --git a/tuts/009-vpc-ipam-gs/vpc-ipam-gs-sdk.sh b/tuts/009-vpc-ipam-gs/vpc-ipam-gs-sdk.sh new file mode 100755 index 00000000..f6207efc --- /dev/null +++ b/tuts/009-vpc-ipam-gs/vpc-ipam-gs-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash vpc-ipam-gs-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/010-cloudmap-service-discovery/cloudmap-service-discovery-sdk.sh b/tuts/010-cloudmap-service-discovery/cloudmap-service-discovery-sdk.sh new file mode 100755 index 00000000..ae4e8ef1 --- /dev/null +++ b/tuts/010-cloudmap-service-discovery/cloudmap-service-discovery-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash cloudmap-service-discovery-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/010-cloudmap-service-discovery/python/requirements.txt b/tuts/010-cloudmap-service-discovery/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/010-cloudmap-service-discovery/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/010-cloudmap-service-discovery/python/scenario_getting_started.py b/tuts/010-cloudmap-service-discovery/python/scenario_getting_started.py new file mode 100644 index 00000000..8d6886b8 --- /dev/null +++ b/tuts/010-cloudmap-service-discovery/python/scenario_getting_started.py @@ -0,0 +1,19 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from servicediscovery_wrapper import CloudMapWrapper + + +def run_scenario(): + client = boto3.client("servicediscovery") + wrapper = CloudMapWrapper(client) + suffix = uuid.uuid4().hex[:8] + print(f"Running CloudMap getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/010-cloudmap-service-discovery/python/servicediscovery_wrapper.py b/tuts/010-cloudmap-service-discovery/python/servicediscovery_wrapper.py new file mode 100644 index 00000000..90fcac12 --- /dev/null +++ b/tuts/010-cloudmap-service-discovery/python/servicediscovery_wrapper.py @@ -0,0 +1,49 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class CloudMapWrapper: + def __init__(self, client): + self.client = client + + def create_namespace(self, name): + """Calls servicediscovery:CreatePublicDnsNamespace.""" + try: + return self.client.create_public_dns_namespace(Name=name)['OperationId'] + logger.info("CreatePublicDnsNamespace succeeded.") + except ClientError: + logger.exception("CreatePublicDnsNamespace failed.") + raise + + def create_service(self, name, namespace_id): + """Calls servicediscovery:CreateService.""" + try: + return self.client.create_service(Name=name, NamespaceId=namespace_id, DnsConfig={'DnsRecords': [{'Type': 'A', 'TTL': 60}]})['Service']['Id'] + logger.info("CreateService succeeded.") + except ClientError: + logger.exception("CreateService failed.") + raise + + def delete_service(self, service_id): + """Calls servicediscovery:DeleteService.""" + try: + self.client.delete_service(Id=service_id) + logger.info("DeleteService succeeded.") + except ClientError: + logger.exception("DeleteService failed.") + raise + + def delete_namespace(self, namespace_id): + """Calls servicediscovery:DeleteNamespace.""" + try: + self.client.delete_namespace(Id=namespace_id) + logger.info("DeleteNamespace succeeded.") + except ClientError: + logger.exception("DeleteNamespace failed.") + raise diff --git a/tuts/010-cloudmap-service-discovery/python/test_servicediscovery.py b/tuts/010-cloudmap-service-discovery/python/test_servicediscovery.py new file mode 100644 index 00000000..74f5be30 --- /dev/null +++ b/tuts/010-cloudmap-service-discovery/python/test_servicediscovery.py @@ -0,0 +1,21 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from servicediscovery_wrapper import CloudMapWrapper + + +@pytest.fixture +def servicediscovery_stubber(): + client = boto3.client("servicediscovery", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(capsys, servicediscovery_stubber): + client, stubber = servicediscovery_stubber + wrapper = CloudMapWrapper(client) + # TODO: add stubbed responses and assertions + assert wrapper is not None diff --git a/tuts/011-getting-started-batch-fargate/batch-fargate-sdk.sh b/tuts/011-getting-started-batch-fargate/batch-fargate-sdk.sh new file mode 100755 index 00000000..684a8de8 --- /dev/null +++ b/tuts/011-getting-started-batch-fargate/batch-fargate-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash batch-fargate-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@" diff --git a/tuts/011-getting-started-batch-fargate/python/batch_wrapper.py b/tuts/011-getting-started-batch-fargate/python/batch_wrapper.py new file mode 100644 index 00000000..51e6e82d --- /dev/null +++ b/tuts/011-getting-started-batch-fargate/python/batch_wrapper.py @@ -0,0 +1,49 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class BatchWrapper: + def __init__(self, client): + self.client = client + + def create_compute_environment(self, name, subnets, security_groups, service_role): + """Calls batch:CreateComputeEnvironment.""" + try: + return self.client.create_compute_environment(computeEnvironmentName=name, type='MANAGED', computeResources={'type': 'FARGATE', 'maxvCpus': 4, 'subnets': subnets, 'securityGroupIds': security_groups}, serviceRole=service_role)['computeEnvironmentArn'] + logger.info("CreateComputeEnvironment succeeded.") + except ClientError: + logger.exception("CreateComputeEnvironment failed.") + raise + + def create_job_queue(self, name, compute_env_arn): + """Calls batch:CreateJobQueue.""" + try: + return self.client.create_job_queue(jobQueueName=name, priority=1, computeEnvironmentOrder=[{'order': 1, 'computeEnvironment': compute_env_arn}])['jobQueueArn'] + logger.info("CreateJobQueue succeeded.") + except ClientError: + logger.exception("CreateJobQueue failed.") + raise + + def delete_job_queue(self, name): + """Calls batch:DeleteJobQueue.""" + try: + self.client.delete_job_queue(jobQueue=name) + logger.info("DeleteJobQueue succeeded.") + except ClientError: + logger.exception("DeleteJobQueue failed.") + raise + + def delete_compute_environment(self, name): + """Calls batch:DeleteComputeEnvironment.""" + try: + self.client.delete_compute_environment(computeEnvironment=name) + logger.info("DeleteComputeEnvironment succeeded.") + except ClientError: + logger.exception("DeleteComputeEnvironment failed.") + raise diff --git a/tuts/011-getting-started-batch-fargate/python/requirements.txt b/tuts/011-getting-started-batch-fargate/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/011-getting-started-batch-fargate/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/011-getting-started-batch-fargate/python/scenario_getting_started.py b/tuts/011-getting-started-batch-fargate/python/scenario_getting_started.py new file mode 100644 index 00000000..8be9954f --- /dev/null +++ b/tuts/011-getting-started-batch-fargate/python/scenario_getting_started.py @@ -0,0 +1,19 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from batch_wrapper import BatchWrapper + + +def run_scenario(): + client = boto3.client("batch") + wrapper = BatchWrapper(client) + suffix = uuid.uuid4().hex[:8] + print(f"Running Batch getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/011-getting-started-batch-fargate/python/test_batch.py b/tuts/011-getting-started-batch-fargate/python/test_batch.py new file mode 100644 index 00000000..9607d96b --- /dev/null +++ b/tuts/011-getting-started-batch-fargate/python/test_batch.py @@ -0,0 +1,21 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from batch_wrapper import BatchWrapper + + +@pytest.fixture +def batch_stubber(): + client = boto3.client("batch", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(capsys, batch_stubber): + client, stubber = batch_stubber + wrapper = BatchWrapper(client) + # TODO: add stubbed responses and assertions + assert wrapper is not None diff --git a/tuts/012-transitgateway-gettingstarted/python/ec2_wrapper.py b/tuts/012-transitgateway-gettingstarted/python/ec2_wrapper.py new file mode 100644 index 00000000..25067f63 --- /dev/null +++ b/tuts/012-transitgateway-gettingstarted/python/ec2_wrapper.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import logging +import boto3 +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) + + +class TransitGatewayWrapper: + def __init__(self, client): + self.client = client + + # TODO: Add wrapper methods matching the CLI tutorial actions diff --git a/tuts/012-transitgateway-gettingstarted/python/requirements.txt b/tuts/012-transitgateway-gettingstarted/python/requirements.txt new file mode 100644 index 00000000..85a50ad4 --- /dev/null +++ b/tuts/012-transitgateway-gettingstarted/python/requirements.txt @@ -0,0 +1,2 @@ +boto3>=1.26 +pytest>=7.0 diff --git a/tuts/012-transitgateway-gettingstarted/python/scenario_getting_started.py b/tuts/012-transitgateway-gettingstarted/python/scenario_getting_started.py new file mode 100644 index 00000000..9a529081 --- /dev/null +++ b/tuts/012-transitgateway-gettingstarted/python/scenario_getting_started.py @@ -0,0 +1,18 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import uuid +import boto3 +from ec2_wrapper import TransitGatewayWrapper + + +def run_scenario(): + client = boto3.client("ec2") + wrapper = TransitGatewayWrapper(client) + print(f"Running TransitGateway getting started scenario...") + # TODO: implement setup, interact, teardown + print("Scenario complete.") + + +if __name__ == "__main__": + run_scenario() diff --git a/tuts/012-transitgateway-gettingstarted/python/test_ec2.py b/tuts/012-transitgateway-gettingstarted/python/test_ec2.py new file mode 100644 index 00000000..0ae44b2c --- /dev/null +++ b/tuts/012-transitgateway-gettingstarted/python/test_ec2.py @@ -0,0 +1,20 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from botocore.stub import Stubber +import boto3 +from ec2_wrapper import TransitGatewayWrapper + + +@pytest.fixture +def stubber(): + client = boto3.client("ec2", region_name="us-east-1") + with Stubber(client) as stubber: + yield client, stubber + + +def test_wrapper_creates(stubber): + client, stub = stubber + wrapper = TransitGatewayWrapper(client) + assert wrapper is not None diff --git a/tuts/012-transitgateway-gettingstarted/transitgateway-gettingstarted-sdk.sh b/tuts/012-transitgateway-gettingstarted/transitgateway-gettingstarted-sdk.sh new file mode 100755 index 00000000..6ac8b4f2 --- /dev/null +++ b/tuts/012-transitgateway-gettingstarted/transitgateway-gettingstarted-sdk.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Run the SDK example for this tutorial. Usage: bash transitgateway-gettingstarted-sdk.sh +source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@"