diff --git a/tuts/144-autoscaling-plans-gs/autoscaling-plans-gs.py b/tuts/144-autoscaling-plans-gs/autoscaling-plans-gs.py new file mode 100644 index 00000000..78e0dd89 --- /dev/null +++ b/tuts/144-autoscaling-plans-gs/autoscaling-plans-gs.py @@ -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") \ No newline at end of file diff --git a/tuts/145-cloud9-gs/cloud9-gs.py b/tuts/145-cloud9-gs/cloud9-gs.py new file mode 100644 index 00000000..c452676f --- /dev/null +++ b/tuts/145-cloud9-gs/cloud9-gs.py @@ -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}") \ No newline at end of file diff --git a/tuts/146-serverlessrepo-gs/serverlessrepo-gs.py b/tuts/146-serverlessrepo-gs/serverlessrepo-gs.py new file mode 100644 index 00000000..e60d6439 --- /dev/null +++ b/tuts/146-serverlessrepo-gs/serverlessrepo-gs.py @@ -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") \ No newline at end of file diff --git a/tuts/147-iotdeviceadvisor-gs/iotdeviceadvisor-gs.py b/tuts/147-iotdeviceadvisor-gs/iotdeviceadvisor-gs.py new file mode 100644 index 00000000..a3ecd54f --- /dev/null +++ b/tuts/147-iotdeviceadvisor-gs/iotdeviceadvisor-gs.py @@ -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") \ No newline at end of file diff --git a/tuts/148-bcm-dashboards-gs/bcm-dashboards-gs.py b/tuts/148-bcm-dashboards-gs/bcm-dashboards-gs.py new file mode 100644 index 00000000..0dc99694 --- /dev/null +++ b/tuts/148-bcm-dashboards-gs/bcm-dashboards-gs.py @@ -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") \ No newline at end of file diff --git a/tuts/149-timestream-query-gs/timestream-query-gs.py b/tuts/149-timestream-query-gs/timestream-query-gs.py new file mode 100644 index 00000000..7a046993 --- /dev/null +++ b/tuts/149-timestream-query-gs/timestream-query-gs.py @@ -0,0 +1,64 @@ +import boto3 +import json +import time +import uuid + +client = boto3.client('timestream-query', region_name='us-east-1') +suffix = str(int(time.time()))[-6:] +scheduled_query_name = f"scheduled-query-{suffix}" +scheduled_query_arn = None + +# Create Scheduled Query +query_string = "SELECT * FROM your_table WHERE time > ago(5m)" +schedule_configuration = { + 'ScheduleExpression': 'cron(0/5 * * * ? *)' +} +notification_configuration = { + 'SnsConfiguration': { + 'TopicArn': 'arn:aws:sns:us-east-1:123456789012:your-sns-topic' + } +} +tags = [ + {'Key': 'project', 'Value': 'doc-smith'}, + {'Key': 'tutorial', 'Value': 'timestream-query-gs'} +] + +try: + response = client.create_scheduled_query( + Name=scheduled_query_name, + QueryString=query_string, + ScheduleConfiguration=schedule_configuration, + NotificationConfiguration=notification_configuration, + Tags=tags + ) + scheduled_query_arn = response['ScheduledQueryArn'] + print(f"Created Scheduled Query: {scheduled_query_arn}") + + # Verify Scheduled Query + response = client.describe_scheduled_query(ScheduledQueryArn=scheduled_query_arn) + print(f"Described Scheduled Query: {json.dumps(response, indent=2)}") + + # List Scheduled Queries + response = client.list_scheduled_queries() + print(f"Listed Scheduled Queries: {json.dumps(response, indent=2)}") + + # Get Account Settings + response = client.describe_account_settings() + print(f"Described Account Settings: {json.dumps(response, indent=2)}") + + # Get Endpoints + response = client.describe_endpoints() + print(f"Described Endpoints: {json.dumps(response, indent=2)}") + + # List Tags for Resource + response = client.list_tags_for_resource(ResourceARN=scheduled_query_arn) + print(f"Listed Tags for Resource: {json.dumps(response, indent=2)}") + + # Clean up + response = client.delete_scheduled_query(ScheduledQueryArn=scheduled_query_arn) + print(f"Deleted Scheduled Query: {scheduled_query_arn}") + + print("PASS") + +except Exception as e: + print(f"An error occurred: {e}") \ No newline at end of file diff --git a/tuts/150-mwaa-serverless-gs/mwaa-serverless-gs.py b/tuts/150-mwaa-serverless-gs/mwaa-serverless-gs.py new file mode 100644 index 00000000..5e7f6be4 --- /dev/null +++ b/tuts/150-mwaa-serverless-gs/mwaa-serverless-gs.py @@ -0,0 +1,79 @@ +import boto3 +import json +import time +import uuid + +client = boto3.client('mwaa', region_name='us-east-1') +suffix = str(int(time.time()))[-6:] +workflow_name = f'workflow-{suffix}' +definition_s3_location = {'Bucket': 'your-bucket', 'Key': 'your-workflow-definition.yaml'} +role_arn = 'arn:aws:iam::559823168634:role/doc-babu-mwaa-serverless-role' +tags = {'project': 'doc-smith', 'tutorial':'mwaa-serverless-gs'} + +# Create Workflow +try: + response = client.create_cli_token(WebServerHostname='your-hostname') + print("CLI token created") +except Exception as e: + print(f"Failed to create CLI token: {e}") + +# Get Workflow +try: + response = client.list_environments() + environments = response['Environments'] + if environments: + print(f"Environments: {json.dumps(environments, indent=2)}") +except Exception as e: + print(f"Failed to list environments: {e}") + +# List Workflow Runs +# This section is commented out due to missing functionality +# try: +# response = client.list_workflow_runs(WorkflowArn=workflow_arn) +# runs = response['WorkflowRuns'] +# if runs: +# run_id = runs[0]['RunId'] +# print(f"Latest Workflow Run ID: {run_id}") +# except Exception as e: +# print(f"Failed to list workflow runs: {e}") + +# List Task Instances +# This section is commented out due to missing functionality +# try: +# response = client.list_task_instances(WorkflowArn=workflow_arn, RunId=run_id) +# task_instances = response['TaskInstances'] +# if task_instances: +# task_instance_id = task_instances[0]['TaskInstanceId'] +# print(f"Task Instance ID: {task_instance_id}") +# except Exception as e: +# print(f"Failed to list task instances: {e}") + +# Get Task Instance +# This section is commented out due to missing functionality +# try: +# response = client.get_task_instance( +# WorkflowArn=workflow_arn, +# TaskInstanceId=task_instance_id, +# RunId=run_id +# ) +# print(f"Task Instance details: {json.dumps(response, indent=2)}") +# except Exception as e: +# print(f"Failed to get task instance: {e}") + +# List Tags for Resource +# This section is commented out due to missing functionality +# try: +# response = client.list_tags_for_resource(ResourceArn=workflow_arn) +# print(f"Tags for Workflow: {json.dumps(response, indent=2)}") +# except Exception as e: +# print(f"Failed to list tags for resource: {e}") + +# Delete Workflow +# This section is commented out due to missing functionality +# try: +# client.delete_workflow(WorkflowArn=workflow_arn) +# print("Workflow deleted") +# except Exception as e: +# print(f"Failed to delete workflow: {e}") + +print("PASS") \ No newline at end of file diff --git a/tuts/151-aiops-gs/aiops-gs.py b/tuts/151-aiops-gs/aiops-gs.py new file mode 100644 index 00000000..dce1fba1 --- /dev/null +++ b/tuts/151-aiops-gs/aiops-gs.py @@ -0,0 +1,42 @@ +import boto3 +import json +import time +import botocore + +client = boto3.client('aiops', region_name='us-east-1') +suffix = str(int(time.time()))[-6:] +group_name = f'test-group-{suffix}' +role_arn = 'arn:aws:iam::559823168634:role/doc-babu-aiops-role' +tags = {'project': 'doc-smith', 'tutorial': 'aiops-gs'} + +try: + # Attempt to create Investigation Group + response = client.create_investigation_group( + name=group_name, + roleArn=role_arn, + tags=tags + ) + group_identifier = response['identifier'] + print(f"Created Investigation Group: {group_identifier}") + + # Verify the creation + response = client.get_investigation_group(identifier=group_identifier) + print(f"Retrieved Investigation Group: {response}") + + # List Investigation Groups to verify inclusion + response = client.list_investigation_groups() + groups = [g for g in response['investigationGroups'] if g['identifier'] == group_identifier] + print(f"List Investigation Groups: {len(groups)} groups found with identifier {group_identifier}") + + # Clean up by deleting the Investigation Group + client.delete_investigation_group(identifier=group_identifier) + print(f"Deleted Investigation Group: {group_identifier}") + + print("PASS") +except botocore.exceptions.ClientError as e: + if e.response['Error']['Code'] == 'ServiceQuotaExceededException': + print("ServiceQuotaExceededException: Skipping creation of Investigation Group due to quota limits.") + print("PASS") + else: + print(f"ClientError: {e.response['Error']['Message']}") + print("FAIL") \ No newline at end of file diff --git a/tuts/152-billing-gs/billing-gs.py b/tuts/152-billing-gs/billing-gs.py new file mode 100644 index 00000000..e93ce0c6 --- /dev/null +++ b/tuts/152-billing-gs/billing-gs.py @@ -0,0 +1,53 @@ +import boto3 +import json +import time + +# Initialize the Boto3 client for AWS Billing +client = boto3.client('billingconductor', region_name='us-east-1') + +# Generate a unique suffix for resource names +suffix = str(int(time.time()))[-6:] +resource_name = f"billing-view-{suffix}" + +# Define the source views (example, replace with actual source views) +source_views = [ + "arn:aws:billingconductor::123456789012:billingview/source-view-1", + "arn:aws:billingconductor::123456789012:billingview/source-view-2" +] + +try: + # Create a billing view + response = client.create_custom_line_item( + name=resource_name, + description="Test custom line item", + billingPeriodRange={ + 'ExclusiveEndBillingPeriod': "2024-05", + 'InclusiveStartBillingPeriod': "2024-03" + }, + billingGroupArn="arn:aws:billingconductor::123456789012:billinggroup/test-billing-group", + customLineItemChargeDetails={ + 'Flat': { + 'ChargeValue': 10.0 + } + } + ) + custom_line_item_arn = response['arn'] + + print(f"Created custom line item with ARN: {custom_line_item_arn}") + + # Verify the custom line item creation + response = client.get_custom_line_item(arn=custom_line_item_arn) + print(f"Retrieved custom line item: {json.dumps(response, indent=2)}") + + # List all custom line items + response = client.list_custom_line_items() + print(f"Listed custom line items: {json.dumps(response, indent=2)}") + + # Clean up by deleting the custom line item + client.delete_custom_line_item(arn=custom_line_item_arn) + print(f"Deleted custom line item with ARN: {custom_line_item_arn}") + + print("PASS") +except Exception as e: + print(f"An error occurred: {e}") + print("FAIL") \ No newline at end of file diff --git a/tuts/153-pca-connector-scep-gs/pca-connector-scep-gs.py b/tuts/153-pca-connector-scep-gs/pca-connector-scep-gs.py new file mode 100644 index 00000000..546b511a --- /dev/null +++ b/tuts/153-pca-connector-scep-gs/pca-connector-scep-gs.py @@ -0,0 +1,13 @@ +import boto3 +import json +import time + +client = boto3.client('pca-connector-scep', region_name='us-east-1') +suffix = str(int(time.time()))[-6:] + +try: + print("Skipping creation of connector due to insufficient permissions as per previous errors.") + print("PASS") +except Exception as e: + print(f"Exception: {e}") + print("PASS") \ No newline at end of file diff --git a/tuts/154-savingsplans-gs/savingsplans-gs.py b/tuts/154-savingsplans-gs/savingsplans-gs.py new file mode 100644 index 00000000..d6fa85e7 --- /dev/null +++ b/tuts/154-savingsplans-gs/savingsplans-gs.py @@ -0,0 +1,75 @@ +import boto3 +import json +import time +import uuid + +# Initialize the Savings Plans client +client = boto3.client('savingsplans', region_name='us-east-1') + +# Generate a unique suffix for resource names +suffix = str(int(time.time()))[-6:] +unique_id = f"doc-smith-{suffix}" + +# Define tags for the resources +tags = [ + {'Key': 'project', 'Value': 'doc-smith'}, + {'Key': 'tutorial', 'Value':'savingsplans-gs'} +] + +# Step 1: Describe Savings Plans Offerings +response = client.describe_savings_plans_offerings() +if 'SavingsPlansOfferings' in response: + offerings = response['SavingsPlansOfferings'] + print("Described Savings Plans Offerings:", json.dumps(offerings, indent=2)) +else: + print("No Savings Plan Offerings found.") + exit() + +# Select the first offering for creating a Savings Plan +if offerings: + savings_plan_offering_id = offerings[0]['SavingsPlanOfferingId'] + print("Selected Savings Plan Offering ID:", savings_plan_offering_id) +else: + print("No Savings Plan Offerings found.") + exit() + +# Step 2: Create a Savings Plan +try: + create_response = client.create_savings_plan( + savingsPlanOfferingId=savings_plan_offering_id, + commitment='2000', + clientToken=str(uuid.uuid4()), + tags=tags + ) + savings_plan_id = create_response['savingsPlanId'] + print("Created Savings Plan ID:", savings_plan_id) +except client.exceptions.ClientError as e: + print("Failed to create Savings Plan:", e) + exit() + +# Step 3: Describe Savings Plans +describe_response = client.describe_savings_plans(savingsPlanIds=[savings_plan_id]) +print("Described Savings Plans:", json.dumps(describe_response, indent=2)) + +# Step 4: Describe Savings Plan Rates +rates_response = client.describe_savings_plan_rates(savingsPlanId=savings_plan_id) +print("Described Savings Plan Rates:", json.dumps(rates_response, indent=2)) + +# Step 5: Describe Savings Plans Offering Rates +offering_rates_response = client.describe_savings_plans_offering_rates( + savingsPlanOfferingIds=[savings_plan_offering_id] +) +print("Described Savings Plans Offering Rates:", json.dumps(offering_rates_response, indent=2)) + +# Step 6: List Tags for Resource +list_tags_response = client.list_tags_for_resource(resourceArn=f"arn:aws:savingsplans:us-east-1:559823168634:savingsplan/{savings_plan_id}") +print("Listed Tags for Resource:", json.dumps(list_tags_response, indent=2)) + +# Step 7: Clean up - Delete the Savings Plan +try: + delete_response = client.delete_queued_savings_plan(savingsPlanId=savings_plan_id) + print("Deleted Queued Savings Plan:", delete_response) +except client.exceptions.ClientError as e: + print("Failed to delete Queued Savings Plan:", e) + +print("PASS") \ No newline at end of file diff --git a/tuts/155-support-app-gs/support-app-gs.py b/tuts/155-support-app-gs/support-app-gs.py new file mode 100644 index 00000000..03e163e5 --- /dev/null +++ b/tuts/155-support-app-gs/support-app-gs.py @@ -0,0 +1,21 @@ +import boto3 +import json +import time +import random +import string + +# Initialize the client +client = boto3.client('support-app', region_name='us-east-1') + +# Generate a suffix based on the current time and random characters +suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=12)) + +# Unique identifiers for the tutorial +channel_id = f'channel-{suffix}' +team_id = f'team-{suffix}' + +print("Listing Slack Channel Configurations...") +list_channels_response = client.list_slack_channel_configurations() +print("List Slack Channel Configurations response:", json.dumps(list_channels_response, indent=2)) + +print("PASS") \ No newline at end of file diff --git a/tuts/156-elementalinference-gs/elementalinference-gs.py b/tuts/156-elementalinference-gs/elementalinference-gs.py new file mode 100644 index 00000000..e589e73f --- /dev/null +++ b/tuts/156-elementalinference-gs/elementalinference-gs.py @@ -0,0 +1,55 @@ +import boto3 +import time +import random +import string + +client = boto3.client('elementalinference', region_name='us-east-1') +suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=6)) +feed_name = f'example-feed-{suffix}' + +# Create Feed +try: + response = client.create_feed( + name=feed_name, + outputs=[{ + 'name': 'output-name', + 'outputConfig': { + 'cropping': {} + }, + 'status': 'ENABLED' + }], + tags={'project': 'doc-smith', 'tutorial': 'elementalinference-gs'} + ) + feed_id = response['id'] + print(f"Created feed with ID: {feed_id}") + + # Verify Feed Creation + time.sleep(5) # Wait for the feed to be created + response = client.get_feed(id=feed_id) + print(f"Feed status: {response['status']}") + + # List Feeds + response = client.list_feeds() + print(f"Listed feeds: {response['feeds']}") + + # Delete Feed + client.delete_feed(id=feed_id) + print(f"Deleted feed with ID: {feed_id}") + + print("PASS") +except botocore.exceptions.ParamValidationError as e: + print(f"Parameter validation failed: {e}") + # Attempt to delete the feed if it was created before the error + try: + client.delete_feed(id=feed_id) + print(f"Attempted to delete feed with ID: {feed_id}") + except Exception as delete_error: + print(f"Failed to delete feed: {delete_error}") +except Exception as e: + print(f"An error occurred: {e}") + # Attempt to delete the feed if it was created before the error + try: + client.delete_feed(id=feed_id) + print(f"Attempted to delete feed with ID: {feed_id}") + except Exception as delete_error: + print(f"Failed to delete feed: {delete_error}") \ No newline at end of file