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à.
Utilizzare GetResourcescon un AWS SDK o CLI
Gli esempi di codice seguenti mostrano come utilizzare GetResources.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nei seguenti esempi di codice:
- CLI
-
- AWS CLI
-
Come ottenere un elenco di risorse per una REST API
Comando:
aws apigateway get-resources --rest-api-id 1234123412
Output:
{
"items": [
{
"path": "/resource/subresource",
"resourceMethods": {
"POST": {}
},
"id": "024ace",
"pathPart": "subresource",
"parentId": "ai5b02"
}
]
}
- Python
-
- SDK per Python (Boto3)
-
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 create_rest_api(self, api_name):
"""
Creates a REST API on API Gateway. The default API has only a root resource
and no HTTP methods.
:param api_name: The name of the API. This descriptive name is not used in
the API path.
:return: The ID of the newly created API.
"""
try:
result = self.apig_client.create_rest_api(name=api_name)
self.api_id = result["id"]
logger.info("Created REST API %s with ID %s.", api_name, self.api_id)
except ClientError:
logger.exception("Couldn't create REST API %s.", api_name)
raise
try:
result = self.apig_client.get_resources(restApiId=self.api_id)
self.root_id = next(
item for item in result["items"] if item["path"] == "/"
)["id"]
except ClientError:
logger.exception("Couldn't get resources for API %s.", self.api_id)
raise
except StopIteration as err:
logger.exception("No root resource found in API %s.", self.api_id)
raise ValueError from err
return self.api_id
- SAP ABAP
-
- SDK per SAP ABAP
-
TRY.
oo_result = lo_agw->getresources(
iv_restapiid = iv_rest_api_id ).
DATA(lt_resources) = oo_result->get_items( ).
DATA(lv_count) = lines( lt_resources ).
MESSAGE 'Found ' && lv_count && ' resources' 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.