There are more AWS SDK examples available in the AWS Doc SDK Examples
API Gateway examples using SDK for Java 2.x
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Java 2.x with API Gateway.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Scenarios are code examples that show you how to accomplish specific tasks by calling multiple functions within a service or combined with other AWS services.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Actions
The following code example shows how to use CreateDeployment
.
- 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.
-
The following code example shows how to use CreateRestApi
.
- 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 createAPI(ApiGatewayClient apiGateway, String restApiId, String restApiName) { try { CreateRestApiRequest request = CreateRestApiRequest.builder() .cloneFrom(restApiId) .description("Created using the Gateway Java API") .name(restApiName) .build(); CreateRestApiResponse response = apiGateway.createRestApi(request); System.out.println("The id of the new api is " + response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
-
For API details, see CreateRestApi in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to use DeleteDeployment
.
- 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 void deleteSpecificDeployment(ApiGatewayClient apiGateway, String restApiId, String deploymentId) { try { DeleteDeploymentRequest request = DeleteDeploymentRequest.builder() .restApiId(restApiId) .deploymentId(deploymentId) .build(); apiGateway.deleteDeployment(request); System.out.println("Deployment was deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
-
For API details, see DeleteDeployment in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to use DeleteRestApi
.
- 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 void deleteAPI(ApiGatewayClient apiGateway, String restApiId) { try { DeleteRestApiRequest request = DeleteRestApiRequest.builder() .restApiId(restApiId) .build(); apiGateway.deleteRestApi(request); System.out.println("The API was successfully deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
-
For API details, see DeleteRestApi in AWS SDK for Java 2.x API Reference.
-
Scenarios
The following code example shows how to create a serverless application that lets users manage photos using labels.
- SDK for Java 2.x
-
Shows how to develop a photo asset management application that detects labels in images using Amazon Rekognition and stores them for later retrieval.
For complete source code and instructions on how to set up and run, see the full example on GitHub
. For a deep dive into the origin of this example see the post on AWS Community
. Services used in this example
API Gateway
DynamoDB
Lambda
Amazon Rekognition
Amazon S3
Amazon SNS
The following code example shows how to create an AWS Lambda function invoked by Amazon API Gateway.
- SDK for Java 2.x
-
Shows how to create an AWS Lambda function by using the Lambda Java runtime API. This example invokes different AWS services to perform a specific use case. This example demonstrates how to create a Lambda function invoked by Amazon API Gateway that scans an Amazon DynamoDB table for work anniversaries and uses Amazon Simple Notification Service (Amazon SNS) to send a text message to your employees that congratulates them at their one year anniversary date.
For complete source code and instructions on how to set up and run, see the full example on GitHub
. Services used in this example
API Gateway
DynamoDB
Lambda
Amazon SNS