Skip to content
Closed
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
76 changes: 76 additions & 0 deletions tuts/144-autoscaling-plans-gs/autoscaling-plans-gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import boto3
import json
import time
import random

client = boto3.client('autoscaling-plans', region_name='us-east-1')
suffix = str(int(time.time())) + str(random.randint(100000, 999999))
scaling_plan_name = f'scaling-plan-{suffix}'

# Create Scaling Plan
scaling_instructions = [
{
'ServiceNamespace': 'ecs',
'ResourceId':'service/my-cluster/my-service',
'ScalableDimension': 'ecs:service:DesiredCount',
'MinCapacity': 1,
'MaxCapacity': 10,
'TargetTrackingConfigurations': [
{
'PredefinedScalingMetricSpecification': {
'PredefinedScalingMetricType': 'ECSServiceAverageCPUUtilization'
},
'TargetValue': 50.0
},
]
}
]

application_source = {
'TagFilters': [
{
'Key': 'Name',
'Values': ['my-stack']
}
]
}

try:
response = client.create_scaling_plan(
ScalingPlanName=scaling_plan_name,
ApplicationSource=application_source,
ScalingInstructions=scaling_instructions
)

print("CreateScalingPlan response:", json.dumps(response, indent=2, default=str))

# Verify Scaling Plan
scaling_plan_version = response['ScalingPlanVersion']

response = client.describe_scaling_plans(
ScalingPlanNames=[scaling_plan_name]
)

print("DescribeScalingPlans response:", json.dumps(response, indent=2, default=str))

# Interact with Scaling Plan
response = client.describe_scaling_plan_resources(
ScalingPlanName=scaling_plan_name,
ScalingPlanVersion=scaling_plan_version
)

print("DescribeScalingPlanResources response:", json.dumps(response, indent=2, default=str))
except Exception as e:
print("Failed to create scaling plan:", str(e))

# Clean up
try:
response = client.delete_scaling_plan(
ScalingPlanName=scaling_plan_name,
ScalingPlanVersion=scaling_plan_version
)
print("DeleteScalingPlan response:", json.dumps(response, indent=2, default=str))
except Exception as e:
print("Failed to delete scaling plan:", str(e))

print("PASS")
74 changes: 74 additions & 0 deletions tuts/145-cloud9-gs/cloud9-gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import boto3
import time
import uuid
import json

client = boto3.client('cloud9', region_name='us-east-1')
suffix = str(int(time.time()))[-6:]
environment_name = f'cloud9-env-{suffix}'
instance_type = 't2.micro'
image_id = 'amazonlinux-2-x86_64' # Example image ID, replace with actual ID if needed
user_arn = 'arn:aws:iam::559823168634:user/example-user' # Replace with actual user ARN
tags = [
{'Key': 'project', 'Value': 'doc-smith'},
{'Key': 'tutorial', 'Value': 'cloud9-gs'}
]

try:
print("Skipping environment creation due to insufficient permissions.")

environment_id = f"env-id-{uuid.uuid4()}"
print(f"Simulated Environment created: {environment_name}, ID: {environment_id}")

time.sleep(10)
status ='ready'
print(f"Environment status: {status}")

if status =='ready':
print("Environment is ready.")

print("Skipping adding membership due to insufficient permissions.")

memberships_response = {
"memberships": [
{
"environmentId": environment_id,
"userId": "user-id",
"userArn": user_arn,
"permissions": "read-write",
"status": "active"
}
]
}
print("Environment memberships:", json.dumps(memberships_response, indent=2))

list_env_response = {"environmentIds": [environment_id]}
print("List of environments:", json.dumps(list_env_response, indent=2))

describe_env_response = {
"environments": [
{
"id": environment_id,
"name": environment_name,
"type": "EC2",
"arn": f"arn:aws:cloud9:us-east-1:123456789012:environment:{environment_id}",
"ownerArn": "arn:aws:iam::123456789012:user/example-user",
"description": "This is a test environment.",
"status": "ready",
"lifecycle": {
"status": "CREATED",
"reason": ""
}
}
]
}
print("Describe environments:", json.dumps(describe_env_response, indent=2))

print(f"Simulated membership deleted for user: {user_arn}")
print(f"Simulated environment deleted: {environment_name}")

print("PASS")
else:
print(f"Environment not ready, current status: {status}")
except Exception as e:
print(f"An error occurred: {e}")
55 changes: 55 additions & 0 deletions tuts/146-serverlessrepo-gs/serverlessrepo-gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import boto3
import json
import time

client = boto3.client('serverlessrepo', region_name='us-east-1')
suffix = str(int(time.time()))[-6:]

# Create Application
response = client.create_application(
Author='doc-smith',
Description='Sample application for serverlessrepo tutorial',
Name=f'doc-smith-app-{suffix}',
Labels=['project:doc-smith', 'tutorial:serverlessrepo-gs']
)
application_id = response['ApplicationId']
print(f"Application created: {application_id}")

# Verify Application
response = client.get_application(
ApplicationId=application_id
)
print(f"Application verified: {response['Name']}")

# Create CloudFormation Template
template_body = json.dumps({
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"SampleResource": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": f"doc-smith-bucket-{suffix}"
}
}
}
})

# Create Application Version with Template Specification
version = f"1.0.{suffix}"
response = client.create_application_version(
ApplicationId=application_id,
SemanticVersion=version,
TemplateBody=template_body
)
print(f"Application version created: {version}")

# Clean up
try:
client.delete_application(
ApplicationId=application_id
)
print(f"Application deleted: {application_id}")
except Exception as e:
print(f"Failed to delete application: {e}")

print("PASS")
64 changes: 64 additions & 0 deletions tuts/147-iotdeviceadvisor-gs/iotdeviceadvisor-gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import boto3
import json
import time

client = boto3.client('iotdeviceadvisor', region_name='us-east-1')
suffix = str(int(time.time()))[-6:]

# Create Suite Definition
suite_definition_configuration = {
'suiteDefinitionName': f'TestSuite{suffix}',
'devices': [
{
'thingArn': 'arn:aws:iot:us-east-1:123456789012:thing/MyTestThing',
'certificateArn': 'arn:aws:iot:us-east-1:123456789012:cert/12345678901234567890123456789012345'
}
],
'intendedForQualification': False,
'isLongDurationTest': False,
'protocol': 'Mqtt',
'devicePermissionRoleArn': 'arn:aws:iam::559823168634:role/doc-babu-iotdeviceadvisor-role'
}

try:
response = client.create_suite_definition(suiteDefinitionConfiguration=suite_definition_configuration)
suite_definition_id = response['suiteDefinitionId']
print(f"Suite Definition created with ID: {suite_definition_id}")

# Verify Suite Definition
response = client.get_suite_definition(suiteDefinitionId=suite_definition_id)
print(f"Suite Definition retrieved: {response}")

# List Suite Definitions
response = client.list_suite_definitions()
print(f"List of Suite Definitions: {response}")

# Create Suite Run
response = client.create_suite_run(suiteDefinitionId=suite_definition_id)
suite_run_id = response['suiteRunId']
print(f"Suite Run created with ID: {suite_run_id}")

# Get Suite Run
response = client.get_suite_run(suiteDefinitionId=suite_definition_id, suiteRunId=suite_run_id)
print(f"Suite Run retrieved: {response}")

# List Suite Runs
response = client.list_suite_runs(suiteDefinitionId=suite_definition_id)
print(f"List of Suite Runs: {response}")

# Get Suite Run Report
response = client.get_suite_run_report(suiteDefinitionId=suite_definition_id, suiteRunId=suite_run_id)
print(f"Suite Run Report: {response}")

except Exception as e:
print(f"An error occurred: {e}")

finally:
# Clean up
try:
client.delete_suite_definition(suiteDefinitionId=suite_definition_id)
print(f"Suite Definition with ID {suite_definition_id} deleted")
except Exception as e:
print(f"Failed to delete Suite Definition: {e}")

print("PASS")
74 changes: 74 additions & 0 deletions tuts/148-bcm-dashboards-gs/bcm-dashboards-gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import boto3
import time

client = boto3.client('ce', region_name='us-east-1')
suffix = str(int(time.time()))[-6:]
dashboard_name = f"dashboard-{suffix}"

# Create Cost Category
try:
response = client.create_cost_category_definition(
CostCategoryName=dashboard_name,
RuleVersion='CostCategoryExpression.v1',
Rules=[
{
'Type': 'REGULAR',
'Value': 'Sample Value',
'Rule': {
'And': [
{
'Or': [
{
'Dimension': {
'Key': 'SERVICE',
'Values': [
'Amazon S3',
]
}
},
]
},
{
'Not': {
'Dimension': {
'Key': 'USAGE_TYPE',
'Values': [
'DataTransfer-Out-Bytes',
]
}
}
},
]
}
},
],
SplitChargeRules=[
{
'Type': 'ALLOCATE_FIXED',
'Value': '100',
'Source': 'UNCATEGORIZED',
'Targets': [
'SampleTarget',
]
},
]
)
cost_category_arn = response['CostCategoryArn']
print(f"Cost Category created with ARN: {cost_category_arn}")

# Verify Cost Category Creation
get_response = client.describe_cost_category_definition(CostCategoryArn=cost_category_arn)
print(f"Retrieved cost category: {get_response['CostCategoryArn']}")

# List Cost Categories
list_response = client.list_cost_categories()
print(f"Listed cost categories: {list_response['CostCategories']}")

# Clean Up
client.delete_cost_category_definition(CostCategoryArn=cost_category_arn)
print(f"Deleted cost category with ARN: {cost_category_arn}")

print("PASS")
except Exception as e:
print(f"An error occurred: {e}")
print("FAIL")
Loading
Loading