There are more AWS SDK examples available in the AWS Doc SDK Examples
Use CreateDeployment
with an AWS SDK or CLI
The following code examples show how to use CreateDeployment
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- CLI
-
- AWS CLI
-
To deploy the configured resources for an API to a new Stage
Command:
aws apigateway create-deployment --rest-api-id
1234123412
--stage-namedev
--stage-description 'Development Stage
' --description 'First deployment to the dev stage
'To deploy the configured resources for an API to an existing stage
Command:
aws apigateway create-deployment --rest-api-id
1234123412
--stage-namedev
--description 'Second deployment to the dev stage
'To deploy the configured resources for an API to an existing stage with Stage Variables
aws apigateway create-deployment --rest-api-id 1234123412 --stage-name dev --description 'Third deployment to the dev stage' --variables key='value',otherKey='otherValue'
-
For API details, see CreateDeployment
in AWS CLI Command Reference.
-
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. public static String createNewDeployment(ApiGatewayClient apiGateway, String restApiId, String stageName) { try { CreateDeploymentRequest request = CreateDeploymentRequest.builder() .restApiId(restApiId) .description("Created using the AWS API Gateway Java API") .stageName(stageName) .build(); CreateDeploymentResponse response = apiGateway.createDeployment(request); System.out.println("The id of the deployment is " + response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
-
For API details, see CreateDeployment in AWS SDK for Java 2.x API Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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 deploy_api(self, stage_name): """ Deploys a REST API. After a REST API is deployed, it can be called from any REST client, such as the Python Requests package or Postman. :param stage_name: The stage of the API to deploy, such as 'test'. :return: The base URL of the deployed REST API. """ try: self.apig_client.create_deployment( restApiId=self.api_id, stageName=stage_name ) self.stage = stage_name logger.info("Deployed stage %s.", stage_name) except ClientError: logger.exception("Couldn't deploy stage %s.", stage_name) raise else: return self.api_url() def api_url(self, resource=None): """ Builds the REST API URL from its parts. :param resource: The resource path to append to the base URL. :return: The REST URL to the specified resource. """ url = ( f"https://{self.api_id}.execute-api.{self.apig_client.meta.region_name}" f".amazonaws.com/{self.stage}" ) if resource is not None: url = f"{url}/{resource}" return url
-
For API details, see CreateDeployment in AWS SDK for Python (Boto3) API Reference.
-