Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions run-sdk.sh
Original file line number Diff line number Diff line change
@@ -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]}") <language>"
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
3 changes: 3 additions & 0 deletions tuts/001-lightsail-gs/lightsail-gs-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Run the SDK example for this tutorial. Usage: bash lightsail-gs-sdk.sh <language>
source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@"
58 changes: 58 additions & 0 deletions tuts/001-lightsail-gs/python/lightsail_wrapper.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tuts/001-lightsail-gs/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3>=1.26
pytest>=7.0
19 changes: 19 additions & 0 deletions tuts/001-lightsail-gs/python/scenario_getting_started.py
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 21 additions & 0 deletions tuts/001-lightsail-gs/python/test_lightsail.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tuts/002-vpc-gs/python/ec2_wrapper.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tuts/002-vpc-gs/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3>=1.26
pytest>=7.0
18 changes: 18 additions & 0 deletions tuts/002-vpc-gs/python/scenario_getting_started.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions tuts/002-vpc-gs/python/test_ec2.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tuts/002-vpc-gs/vpc-gs-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Run the SDK example for this tutorial. Usage: bash vpc-gs-sdk.sh <language>
source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@"
2 changes: 2 additions & 0 deletions tuts/003-s3-gettingstarted/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3>=1.26
pytest>=7.0
76 changes: 76 additions & 0 deletions tuts/003-s3-gettingstarted/python/s3_wrapper.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions tuts/003-s3-gettingstarted/python/scenario_getting_started.py
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 21 additions & 0 deletions tuts/003-s3-gettingstarted/python/test_s3.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tuts/003-s3-gettingstarted/s3-gettingstarted-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Run the SDK example for this tutorial. Usage: bash s3-gettingstarted-sdk.sh <language>
source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Run the SDK example for this tutorial. Usage: bash cloudmap-custom-attributes-sdk.sh <language>
source "$(cd "$(dirname "$0")/../.." && pwd)/run-sdk.sh" "$@"
2 changes: 2 additions & 0 deletions tuts/004-cloudmap-custom-attributes/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3>=1.26
pytest>=7.0
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading