AWS Doc SDK Examples GitHub リポジトリには他にも AWS SDK例があります。
翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
または CreateResource
で を使用する AWS SDK CLI
以下のコード例は、CreateResource
の使用方法を示しています。
アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。
- CLI
-
- AWS CLI
-
でリソースを作成するには API
コマンド:
aws apigateway create-resource --rest-api-id 1234123412
--parent-id a1b2c3
--path-part 'new-resource
'
- Python
-
- SDK for Python (Boto3)
-
については、「」を参照してください GitHub。用例一覧を検索し、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