Auto Scaling examples using SDK for SAP ABAP - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Auto Scaling examples using SDK for SAP ABAP

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for SAP ABAP with Auto Scaling.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use CreateAutoScalingGroup.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

DATA lo_launch_template TYPE REF TO /aws1/cl_asclaunchtemplatespec. " Example: iv_group_name = 'my-auto-scaling-group' " Example: iv_launch_template_name = 'my-launch-template' " Example: iv_min_size = 1 " Example: iv_max_size = 3 " Example: iv_vpc_zone_identifier = 'subnet-12345,subnet-67890' (for VPC) TRY. " Create launch template specification lo_launch_template = NEW /aws1/cl_asclaunchtemplatespec( iv_launchtemplatename = iv_launch_template_name iv_version = '$Default' ). " Create the Auto Scaling group " Use VPCZoneIdentifier for VPC subnets, or AvailabilityZones for EC2-Classic IF iv_vpc_zone_identifier IS NOT INITIAL. " VPC-based deployment - use subnet IDs ao_asc->createautoscalinggroup( iv_autoscalinggroupname = iv_group_name iv_vpczoneidentifier = iv_vpc_zone_identifier io_launchtemplate = lo_launch_template iv_minsize = iv_min_size iv_maxsize = iv_max_size ). ELSE. " EC2-Classic or default VPC - use availability zones ao_asc->createautoscalinggroup( iv_autoscalinggroupname = iv_group_name it_availabilityzones = it_group_zones io_launchtemplate = lo_launch_template iv_minsize = iv_min_size iv_maxsize = iv_max_size ). ENDIF. " Wait for the group to be created (simplified - in production use proper polling) WAIT UP TO 10 SECONDS. MESSAGE 'Auto Scaling group created successfully' TYPE 'I'. CATCH /aws1/cx_ascalreadyexistsfault INTO DATA(lo_already_exists). RAISE EXCEPTION lo_already_exists. CATCH /aws1/cx_asclimitexceededfault INTO DATA(lo_limit_exceeded). RAISE EXCEPTION lo_limit_exceeded. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use DeleteAutoScalingGroup.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_group_name = 'my-auto-scaling-group' TRY. ao_asc->deleteautoscalinggroup( iv_autoscalinggroupname = iv_group_name ). " Wait for the group to be deleted (simplified - in production use proper polling) WAIT UP TO 10 SECONDS. MESSAGE 'Auto Scaling group deleted successfully' TYPE 'I'. CATCH /aws1/cx_ascscaactivityinprg00 INTO DATA(lo_activity_in_progress). RAISE EXCEPTION lo_activity_in_progress. CATCH /aws1/cx_ascresourceinusefault INTO DATA(lo_resource_in_use). RAISE EXCEPTION lo_resource_in_use. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use DescribeAutoScalingGroups.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

DATA lt_group_names TYPE /aws1/cl_ascautoscgroupnames_w=>tt_autoscalinggroupnames. DATA lo_group_name TYPE REF TO /aws1/cl_ascautoscgroupnames_w. " Example: iv_group_name = 'my-auto-scaling-group' TRY. " Build group names parameter CREATE OBJECT lo_group_name EXPORTING iv_value = iv_group_name. APPEND lo_group_name TO lt_group_names. " Describe the Auto Scaling group DATA(lo_output) = ao_asc->describeautoscalinggroups( it_autoscalinggroupnames = lt_group_names ). " Return the first (and only) group in the result DATA(lt_groups) = lo_output->get_autoscalinggroups( ). IF lines( lt_groups ) > 0. READ TABLE lt_groups INDEX 1 INTO DATA(lo_group). oo_output = lo_group. ENDIF. MESSAGE 'Auto Scaling group information retrieved successfully' TYPE 'I'. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use DescribeAutoScalingInstances.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: it_instance_ids contains a list of instance IDs TRY. DATA(lo_output) = ao_asc->describeautoscalinginstances( it_instanceids = it_instance_ids ). ot_output = lo_output->get_autoscalinginstances( ). MESSAGE 'Auto Scaling instances information retrieved successfully' TYPE 'I'. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use DescribeScalingActivities.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_group_name = 'my-auto-scaling-group' TRY. DATA(lo_output) = ao_asc->describescalingactivities( iv_autoscalinggroupname = iv_group_name ). ot_output = lo_output->get_activities( ). MESSAGE 'Scaling activities retrieved successfully' TYPE 'I'. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use DisableMetricsCollection.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_group_name = 'my-auto-scaling-group' TRY. ao_asc->disablemetricscollection( iv_autoscalinggroupname = iv_group_name ). MESSAGE 'Metrics collection disabled successfully' TYPE 'I'. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use EnableMetricsCollection.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_group_name = 'my-auto-scaling-group' " Example: it_metrics contains list of metrics like 'GroupMinSize', 'GroupMaxSize', etc. TRY. ao_asc->enablemetricscollection( iv_autoscalinggroupname = iv_group_name it_metrics = it_metrics iv_granularity = '1Minute' ). MESSAGE 'Metrics collection enabled successfully' TYPE 'I'. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use SetDesiredCapacity.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_group_name = 'my-auto-scaling-group' " Example: iv_capacity = 2 TRY. ao_asc->setdesiredcapacity( iv_autoscalinggroupname = iv_group_name iv_desiredcapacity = iv_capacity iv_honorcooldown = abap_false ). MESSAGE 'Desired capacity set successfully' TYPE 'I'. CATCH /aws1/cx_ascscaactivityinprg00 INTO DATA(lo_activity_in_progress). RAISE EXCEPTION lo_activity_in_progress. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use TerminateInstanceInAutoScalingGroup.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_instance_id = 'i-1234567890abcdef0' " Example: iv_decrease_capacity = abap_true TRY. DATA(lo_output) = ao_asc->terminateinstinautoscgroup( iv_instanceid = iv_instance_id iv_shoulddecrementdesiredcap = iv_decrease_capacity ). oo_output = lo_output->get_activity( ). MESSAGE 'Instance terminated successfully' TYPE 'I'. CATCH /aws1/cx_ascscaactivityinprg00 INTO DATA(lo_activity_in_progress). RAISE EXCEPTION lo_activity_in_progress. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.

The following code example shows how to use UpdateAutoScalingGroup.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

" Example: iv_group_name = 'my-auto-scaling-group' " Example: iv_max_size = 5 TRY. ao_asc->updateautoscalinggroup( iv_autoscalinggroupname = iv_group_name iv_maxsize = iv_max_size iv_minsize = iv_min_size ). MESSAGE 'Auto Scaling group updated successfully' TYPE 'I'. CATCH /aws1/cx_ascresrccontionfault INTO DATA(lo_contention). RAISE EXCEPTION lo_contention. CATCH /aws1/cx_ascscaactivityinprg00 INTO DATA(lo_activity_in_progress). RAISE EXCEPTION lo_activity_in_progress. CATCH /aws1/cx_rt_generic INTO DATA(lo_generic_exception). RAISE EXCEPTION lo_generic_exception. ENDTRY.