Weitere AWS-SDK-Beispiele sind im GitHub-Repository Beispiele für AWS Doc SDKs
Beispiele für Amazon EC2 unter Verwendung von SDK für SAP ABAP
Die folgenden Codebeispiele zeigen, wie Sie Aktionen durchführen und gängige Szenarien implementieren, indem Sie AWS-SDK für SAP ABAP mit Amazon EC2 nutzen.
Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Während Aktionen Ihnen zeigen, wie Sie einzelne Servicefunktionen aufrufen, können Sie Aktionen im Kontext der zugehörigen Szenarien anzeigen.
Jedes Beispiel enthält einen Link zum vollständigen Quellcode, wo Sie Anweisungen zum Einrichten und Ausführen des Codes im Kodex finden.
Themen
Aktionen
Die folgenden Codebeispiele zeigen, wie AllocateAddress verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->allocateaddress( iv_domain = 'vpc' ). " oo_result is returned for testing purposes. " MESSAGE 'Allocated an Elastic IP address.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter AllocateAddress in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie AssociateAddress verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->associateaddress( " oo_result is returned for testing purposes. " iv_allocationid = iv_allocation_id iv_instanceid = iv_instance_id ). MESSAGE 'Associated an Elastic IP address with an EC2 instance.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter AssociateAddress in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie CreateKeyPair verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->createkeypair( iv_keyname = iv_key_name ). " oo_result is returned for testing purposes. " MESSAGE 'Amazon EC2 key pair created.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter CreateKeyPair in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie CreateSecurityGroup verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->createsecuritygroup( " oo_result is returned for testing purposes. " iv_description = 'Security group example' iv_groupname = iv_security_group_name iv_vpcid = iv_vpc_id ). MESSAGE 'Security group created.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter CreateSecurityGroup in der API-Referenz für das AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DeleteKeyPair verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. lo_ec2->deletekeypair( iv_keyname = iv_key_name ). MESSAGE 'Amazon EC2 key pair deleted.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DeleteKeyPair in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DeleteSecurityGroup verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. lo_ec2->deletesecuritygroup( iv_groupid = iv_security_group_id ). MESSAGE 'Security group deleted.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DeleteSecurityGroup in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DescribeAddresses verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->describeaddresses( ). " oo_result is returned for testing purposes. " DATA(lt_addresses) = oo_result->get_addresses( ). MESSAGE 'Retrieved information about Elastic IP addresses.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DescribeAddresses in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DescribeAvailabilityZones verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->describeavailabilityzones( ). " oo_result is returned for testing purposes. " DATA(lt_zones) = oo_result->get_availabilityzones( ). MESSAGE 'Retrieved information about Availability Zones.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DescribeAvailabilityZones in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DescribeInstances verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->describeinstances( ). " oo_result is returned for testing purposes. " " Retrieving details of EC2 instances. " DATA: lv_istance_id TYPE /aws1/ec2string, lv_status TYPE /aws1/ec2instancestatename, lv_instance_type TYPE /aws1/ec2instancetype, lv_image_id TYPE /aws1/ec2string. LOOP AT oo_result->get_reservations( ) INTO DATA(lo_reservation). LOOP AT lo_reservation->get_instances( ) INTO DATA(lo_instance). lv_istance_id = lo_instance->get_instanceid( ). lv_status = lo_instance->get_state( )->get_name( ). lv_instance_type = lo_instance->get_instancetype( ). lv_image_id = lo_instance->get_imageid( ). ENDLOOP. ENDLOOP. MESSAGE 'Retrieved information about EC2 instances.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DescribeInstances in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DescribeKeyPairs verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->describekeypairs( ). " oo_result is returned for testing purposes. " DATA(lt_key_pairs) = oo_result->get_keypairs( ). MESSAGE 'Retrieved information about key pairs.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DescribeKeyPairs in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DescribeRegions verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. oo_result = lo_ec2->describeregions( ). " oo_result is returned for testing purposes. " DATA(lt_regions) = oo_result->get_regions( ). MESSAGE 'Retrieved information about Regions.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DescribeRegions in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie DescribeSecurityGroups verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. DATA lt_group_ids TYPE /aws1/cl_ec2groupidstrlist_w=>tt_groupidstringlist. APPEND NEW /aws1/cl_ec2groupidstrlist_w( iv_value = iv_group_id ) TO lt_group_ids. oo_result = lo_ec2->describesecuritygroups( it_groupids = lt_group_ids ). " oo_result is returned for testing purposes. " DATA(lt_security_groups) = oo_result->get_securitygroups( ). MESSAGE 'Retrieved information about security groups.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter DescribeSecurityGroups in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie MonitorInstances verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. DATA lt_instance_ids TYPE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist. APPEND NEW /aws1/cl_ec2instidstringlist_w( iv_value = iv_instance_id ) TO lt_instance_ids. "Perform dry run" TRY. " DryRun is set to true. This checks for the required permissions to monitor the instance without actually making the request. " lo_ec2->monitorinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_true ). CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). " If the error code returned is `DryRunOperation`, then you have the required permissions to monitor this instance. " IF lo_exception->av_err_code = 'DryRunOperation'. MESSAGE 'Dry run to enable detailed monitoring completed.' TYPE 'I'. " DryRun is set to false to enable detailed monitoring. " lo_ec2->monitorinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_false ). MESSAGE 'Detailed monitoring enabled.' TYPE 'I'. " If the error code returned is `UnauthorizedOperation`, then you don't have the required permissions to monitor this instance. " ELSEIF lo_exception->av_err_code = 'UnauthorizedOperation'. MESSAGE 'Dry run to enable detailed monitoring failed. User does not have the permissions to monitor the instance.' TYPE 'E'. ELSE. DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDIF. ENDTRY.-
Weitere API-Informationen finden Sie unter MonitorInstances in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie RebootInstances verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. DATA lt_instance_ids TYPE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist. APPEND NEW /aws1/cl_ec2instidstringlist_w( iv_value = iv_instance_id ) TO lt_instance_ids. "Perform dry run" TRY. " DryRun is set to true. This checks for the required permissions to reboot the instance without actually making the request. " lo_ec2->rebootinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_true ). CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). " If the error code returned is `DryRunOperation`, then you have the required permissions to reboot this instance. " IF lo_exception->av_err_code = 'DryRunOperation'. MESSAGE 'Dry run to reboot instance completed.' TYPE 'I'. " DryRun is set to false to make a reboot request. " lo_ec2->rebootinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_false ). MESSAGE 'Instance rebooted.' TYPE 'I'. " If the error code returned is `UnauthorizedOperation`, then you don't have the required permissions to reboot this instance. " ELSEIF lo_exception->av_err_code = 'UnauthorizedOperation'. MESSAGE 'Dry run to reboot instance failed. User does not have permissions to reboot the instance.' TYPE 'E'. ELSE. DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDIF. ENDTRY.-
Weitere API-Informationen finden Sie unter RebootInstances in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie ReleaseAddress verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. TRY. lo_ec2->releaseaddress( iv_allocationid = iv_allocation_id ). MESSAGE 'Elastic IP address released.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter ReleaseAddress in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie RunInstances verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. " Create tags for resource created during instance launch. " DATA lt_tagspecifications TYPE /aws1/cl_ec2tagspecification=>tt_tagspecificationlist. DATA ls_tagspecifications LIKE LINE OF lt_tagspecifications. ls_tagspecifications = NEW /aws1/cl_ec2tagspecification( iv_resourcetype = 'instance' it_tags = VALUE /aws1/cl_ec2tag=>tt_taglist( ( NEW /aws1/cl_ec2tag( iv_key = 'Name' iv_value = iv_tag_value ) ) ) ). APPEND ls_tagspecifications TO lt_tagspecifications. TRY. " Create/launch Amazon Elastic Compute Cloud (Amazon EC2) instance. " oo_result = lo_ec2->runinstances( " oo_result is returned for testing purposes. " iv_imageid = iv_ami_id iv_instancetype = 't3.micro' iv_maxcount = 1 iv_mincount = 1 it_tagspecifications = lt_tagspecifications iv_subnetid = iv_subnet_id ). MESSAGE 'EC2 instance created.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
Weitere API-Informationen finden Sie unter RunInstances in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie StartInstances verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. DATA lt_instance_ids TYPE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist. APPEND NEW /aws1/cl_ec2instidstringlist_w( iv_value = iv_instance_id ) TO lt_instance_ids. "Perform dry run" TRY. " DryRun is set to true. This checks for the required permissions to start the instance without actually making the request. " lo_ec2->startinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_true ). CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). " If the error code returned is `DryRunOperation`, then you have the required permissions to start this instance. " IF lo_exception->av_err_code = 'DryRunOperation'. MESSAGE 'Dry run to start instance completed.' TYPE 'I'. " DryRun is set to false to start instance. " oo_result = lo_ec2->startinstances( " oo_result is returned for testing purposes. " it_instanceids = lt_instance_ids iv_dryrun = abap_false ). MESSAGE 'Successfully started the EC2 instance.' TYPE 'I'. " If the error code returned is `UnauthorizedOperation`, then you don't have the required permissions to start this instance. " ELSEIF lo_exception->av_err_code = 'UnauthorizedOperation'. MESSAGE 'Dry run to start instance failed. User does not have permissions to start the instance.' TYPE 'E'. ELSE. DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDIF. ENDTRY.-
Weitere API-Informationen finden Sie unter StartInstances in der API-Referenz zum AWS-SDK für SAP ABAP.
-
Die folgenden Codebeispiele zeigen, wie StopInstances verwendet wird.
- SDK für SAP ABAP
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Codebeispiel-Repository
einrichten und ausführen. DATA lt_instance_ids TYPE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist. APPEND NEW /aws1/cl_ec2instidstringlist_w( iv_value = iv_instance_id ) TO lt_instance_ids. "Perform dry run" TRY. " DryRun is set to true. This checks for the required permissions to stop the instance without actually making the request. " lo_ec2->stopinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_true ). CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). " If the error code returned is `DryRunOperation`, then you have the required permissions to stop this instance. " IF lo_exception->av_err_code = 'DryRunOperation'. MESSAGE 'Dry run to stop instance completed.' TYPE 'I'. " DryRun is set to false to stop instance. " oo_result = lo_ec2->stopinstances( " oo_result is returned for testing purposes. " it_instanceids = lt_instance_ids iv_dryrun = abap_false ). MESSAGE 'Successfully stopped the EC2 instance.' TYPE 'I'. " If the error code returned is `UnauthorizedOperation`, then you don't have the required permissions to stop this instance. " ELSEIF lo_exception->av_err_code = 'UnauthorizedOperation'. MESSAGE 'Dry run to stop instance failed. User does not have permissions to stop the instance.' TYPE 'E'. ELSE. DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDIF. ENDTRY.-
Weitere API-Informationen finden Sie unter StopInstances in der API-Referenz zum AWS-SDK für SAP ABAP.
-