View a markdown version of this page

Esempi per Amazon EC2 con SDK per SAP ABAP - AWS Esempi di codice SDK

Sono disponibili altri esempi di AWS SDK nel repository AWS Doc SDK Examples. GitHub

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Esempi per Amazon EC2 con SDK per SAP ABAP

I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando l' AWS SDK per SAP ABAP con Amazon EC2.

Le azioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le azioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.

Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Azioni

L’esempio di codice seguente mostra come utilizzare AllocateAddress.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta AllocateAddress la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare AssociateAddress.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta AssociateAddress la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare AuthorizeSecurityGroupIngress.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

" Create IP permissions for SSH access (port 22) " iv_cidr_ip = '192.0.2.0/24' DATA lt_ip_permissions TYPE /aws1/cl_ec2ippermission=>tt_ippermissionlist. DATA(lo_ip_permission) = NEW /aws1/cl_ec2ippermission( iv_ipprotocol = 'tcp' iv_fromport = 22 iv_toport = 22 it_ipranges = VALUE /aws1/cl_ec2iprange=>tt_iprangelist( ( NEW /aws1/cl_ec2iprange( iv_cidrip = iv_cidr_ip ) ) ) ). APPEND lo_ip_permission TO lt_ip_permissions. TRY. oo_result = lo_ec2->authsecuritygroupingress( " oo_result is returned for testing purposes. " iv_groupid = iv_group_id it_ippermissions = lt_ip_permissions ). MESSAGE 'Authorized ingress rule for security group.' 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.

L’esempio di codice seguente mostra come utilizzare CreateKeyPair.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta CreateKeyPair la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare CreateSecurityGroup.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.

L’esempio di codice seguente mostra come utilizzare CreateVpc.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

" iv_cidr_block = '10.0.0.0/16' TRY. oo_result = lo_ec2->createvpc( iv_cidrblock = iv_cidr_block ). " oo_result is returned for testing purposes. " DATA(lv_vpc_id) = oo_result->get_vpc( )->get_vpcid( ). MESSAGE 'Created VPC.' 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.
  • Per i dettagli sull'API, consulta il riferimento CreateVpc all'API ABAP AWS SDK for SAP.

L’esempio di codice seguente mostra come utilizzare CreateVpcEndpoint.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

" iv_vpc_id = 'vpc-abc123' " iv_service_name = 'com.amazonaws.region.service' TRY. oo_result = lo_ec2->createvpcendpoint( " oo_result is returned for testing purposes. " iv_vpcid = iv_vpc_id iv_servicename = iv_service_name it_routetableids = it_route_table_ids ). DATA(lv_vpc_endpoint_id) = oo_result->get_vpcendpoint( )->get_vpcendpointid( ). MESSAGE 'Created VPC endpoint.' 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.
  • Per i dettagli sulle API, consulta CreateVpcEndpoint la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DeleteKeyPair.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta DeleteKeyPair la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DeleteSecurityGroup.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.

L’esempio di codice seguente mostra come utilizzare DeleteVpc.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

TRY. lo_ec2->deletevpc( iv_vpcid = iv_vpc_id ). MESSAGE 'Deleted VPC.' 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.
  • Per i dettagli sulle API, consulta DeleteVpc la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DeleteVpcEndpoints.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

TRY. lo_ec2->deletevpcendpoints( it_vpcendpointids = it_vpc_endpoint_ids ). MESSAGE 'Deleted VPC endpoint(s).' 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.
  • Per i dettagli sulle API, consulta DeleteVpcEndpoints la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DescribeAddresses.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta DescribeAddresses la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DescribeAvailabilityZones.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.

L’esempio di codice seguente mostra come utilizzare DescribeImages.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

TRY. oo_result = lo_ec2->describeimages( it_imageids = it_image_ids ). " oo_result is returned for testing purposes. " DATA(lt_images) = oo_result->get_images( ). MESSAGE 'Retrieved information about Amazon Machine Images (AMIs).' 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.
  • Per i dettagli sulle API, consulta DescribeImages la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DescribeInstanceTypes.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

" Create filters for architecture and instance type patterns " iv_architecture = 'x86_64' DATA lt_filters TYPE /aws1/cl_ec2filter=>tt_filterlist. APPEND NEW /aws1/cl_ec2filter( iv_name = 'processor-info.supported-architecture' it_values = VALUE /aws1/cl_ec2valuestringlist_w=>tt_valuestringlist( ( NEW /aws1/cl_ec2valuestringlist_w( iv_architecture ) ) ) ) TO lt_filters. " Filter for instance type patterns like '*.micro', '*.small' APPEND NEW /aws1/cl_ec2filter( iv_name = 'instance-type' it_values = VALUE /aws1/cl_ec2valuestringlist_w=>tt_valuestringlist( ( NEW /aws1/cl_ec2valuestringlist_w( '*.micro' ) ) ( NEW /aws1/cl_ec2valuestringlist_w( '*.small' ) ) ) ) TO lt_filters. TRY. oo_result = lo_ec2->describeinstancetypes( it_filters = lt_filters ). " oo_result is returned for testing purposes. " DATA(lt_instance_types) = oo_result->get_instancetypes( ). MESSAGE 'Retrieved information about EC2 instance types.' 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.

L’esempio di codice seguente mostra come utilizzare DescribeInstances.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta DescribeInstances la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DescribeKeyPairs.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta DescribeKeyPairs la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DescribeRegions.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta DescribeRegions la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare DescribeRouteTables.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

" Create filter for VPC ID " iv_vpc_id = 'vpc-abc123' DATA lt_filters TYPE /aws1/cl_ec2filter=>tt_filterlist. APPEND NEW /aws1/cl_ec2filter( iv_name = 'vpc-id' it_values = VALUE /aws1/cl_ec2valuestringlist_w=>tt_valuestringlist( ( NEW /aws1/cl_ec2valuestringlist_w( iv_vpc_id ) ) ) ) TO lt_filters. TRY. oo_result = lo_ec2->describeroutetables( it_filters = lt_filters ). " oo_result is returned for testing purposes. " DATA(lt_route_tables) = oo_result->get_routetables( ). MESSAGE 'Retrieved information about route tables.' 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.

L’esempio di codice seguente mostra come utilizzare DescribeSecurityGroups.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.

L’esempio di codice seguente mostra come utilizzare MonitorInstances.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta MonitorInstances la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare RebootInstances.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta RebootInstances la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare ReleaseAddress.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta ReleaseAddress la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare RunInstances.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

" 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.
  • Per i dettagli sulle API, consulta RunInstances la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare StartInstances.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta StartInstances la sezione AWS SDK for SAP ABAP API Reference.

L’esempio di codice seguente mostra come utilizzare StopInstances.

SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

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.
  • Per i dettagli sulle API, consulta StopInstances la sezione AWS SDK for SAP ABAP API Reference.