Skip to content

/AWS1/CL_EC2=>TERMINATEINSTANCES00()

About TerminateInstances

Shuts down the specified instances. This operation is idempotent; if you terminate an instance more than once, each call succeeds.

If you specify multiple instances and the request fails (for example, because of a single incorrect instance ID), none of the instances are terminated.

If you terminate multiple instances across multiple Availability Zones, and one or more of the specified instances are enabled for termination protection, the request fails with the following results:

  • The specified instances that are in the same Availability Zone as the protected instance are not terminated.

  • The specified instances that are in different Availability Zones, where no other specified instances are protected, are successfully terminated.

For example, say you have the following instances:

  • Instance A: us-east-1a; Not protected

  • Instance B: us-east-1a; Not protected

  • Instance C: us-east-1b; Protected

  • Instance D: us-east-1b; not protected

If you attempt to terminate all of these instances in the same request, the request reports failure with the following results:

  • Instance A and Instance B are successfully terminated because none of the specified instances in us-east-1a are enabled for termination protection.

  • Instance C and Instance D fail to terminate because at least one of the specified instances in us-east-1b (Instance C) is enabled for termination protection.

Terminated instances remain visible after termination (for approximately one hour).

By default, Amazon EC2 deletes all EBS volumes that were attached when the instance launched. Volumes attached after instance launch continue running.

You can stop, start, and terminate EBS-backed instances. You can only terminate instance store-backed instances. What happens to an instance differs if you stop or terminate it. For example, when you stop an instance, the root device and any other devices attached to the instance persist. When you terminate an instance, any attached EBS volumes with the DeleteOnTermination block device mapping parameter set to true are automatically deleted. For more information about the differences between stopping and terminating instances, see Amazon EC2 instance state changes in the Amazon EC2 User Guide.

For information about troubleshooting, see Troubleshooting terminating your instance in the Amazon EC2 User Guide.

Method Signature

IMPORTING

Required arguments:

it_instanceids TYPE /AWS1/CL_EC2INSTIDSTRINGLIST_W=>TT_INSTANCEIDSTRINGLIST TT_INSTANCEIDSTRINGLIST

The IDs of the instances.

Constraints: Up to 1000 instance IDs. We recommend breaking up this request into smaller batches.

Optional arguments:

iv_dryrun TYPE /AWS1/EC2BOOLEAN /AWS1/EC2BOOLEAN

Checks whether you have the required permissions for the operation, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

RETURNING

oo_output TYPE REF TO /aws1/cl_ec2terminateinstsrslt /AWS1/CL_EC2TERMINATEINSTSRSLT

Domain /AWS1/RT_ACCOUNT_ID
Primitive Type NUMC

Examples

Syntax Example

This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.

DATA(lo_result) = lo_client->/aws1/if_ec2~terminateinstances00(
  it_instanceids = VALUE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist(
    ( new /aws1/cl_ec2instidstringlist_w( |string| ) )
  )
  iv_dryrun = ABAP_TRUE
).

This is an example of reading all possible response values

lo_result = lo_result.
IF lo_result IS NOT INITIAL.
  LOOP AT lo_result->get_terminatinginstances( ) into lo_row.
    lo_row_1 = lo_row.
    IF lo_row_1 IS NOT INITIAL.
      lv_string = lo_row_1->get_instanceid( ).
      lo_instancestate = lo_row_1->get_currentstate( ).
      IF lo_instancestate IS NOT INITIAL.
        lv_integer = lo_instancestate->get_code( ).
        lv_instancestatename = lo_instancestate->get_name( ).
      ENDIF.
      lo_instancestate = lo_row_1->get_previousstate( ).
      IF lo_instancestate IS NOT INITIAL.
        lv_integer = lo_instancestate->get_code( ).
        lv_instancestatename = lo_instancestate->get_name( ).
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDIF.

To terminate an EC2 instance

This example terminates the specified EC2 instance.

DATA(lo_result) = lo_client->/aws1/if_ec2~terminateinstances00(
  it_instanceids = VALUE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist(
    ( new /aws1/cl_ec2instidstringlist_w( |i-1234567890abcdef0| ) )
  )
).