Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan CreateResource dengan AWS SDK atau CLI
Contoh kode berikut menunjukkan cara menggunakanCreateResource.
Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:
- CLI
-
- AWS CLI
-
Untuk membuat sumber daya di API
Perintah:
aws apigateway create-resource --rest-api-id 1234123412 --parent-id a1b2c3 --path-part 'new-resource'
- Python
-
- SDK untuk Python (Boto3)
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
class ApiGatewayToService:
"""
Encapsulates Amazon API Gateway functions that are used to create a REST API that
integrates with another AWS service.
"""
def __init__(self, apig_client):
"""
:param apig_client: A Boto3 API Gateway client.
"""
self.apig_client = apig_client
self.api_id = None
self.root_id = None
self.stage = None
def add_rest_resource(self, parent_id, resource_path):
"""
Adds a resource to a REST API.
:param parent_id: The ID of the parent resource.
:param resource_path: The path of the new resource, relative to the parent.
:return: The ID of the new resource.
"""
try:
result = self.apig_client.create_resource(
restApiId=self.api_id, parentId=parent_id, pathPart=resource_path
)
resource_id = result["id"]
logger.info("Created resource %s.", resource_path)
except ClientError:
logger.exception("Couldn't create resource %s.", resource_path)
raise
else:
return resource_id
- SAP ABAP
-
- SDK for SAP ABAP
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
TRY.
oo_result = lo_agw->createresource(
iv_restapiid = iv_rest_api_id
iv_parentid = iv_parent_id
iv_pathpart = iv_resource_path ).
DATA(lv_resource_id) = oo_result->get_id( ).
MESSAGE 'Resource created with ID: ' && lv_resource_id TYPE 'I'.
CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request).
MESSAGE lo_bad_request->get_text( ) TYPE 'I'.
RAISE EXCEPTION lo_bad_request.
CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found).
MESSAGE lo_not_found->get_text( ) TYPE 'I'.
RAISE EXCEPTION lo_not_found.
CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many).
MESSAGE lo_too_many->get_text( ) TYPE 'I'.
RAISE EXCEPTION lo_too_many.
ENDTRY.