diff --git a/.doc_gen/cross-content/cross_FSA_Java_block.xml b/.doc_gen/cross-content/cross_FSA_Java_block.xml
new file mode 100644
index 00000000000..be14e657e61
--- /dev/null
+++ b/.doc_gen/cross-content/cross_FSA_Java_block.xml
@@ -0,0 +1,33 @@
+
+
+ %phrases-shared;
+]>
+
+
+ This example application analyzes and stores customer feedback cards. Specifically,
+ it fulfills the need of a fictitious hotel in New York City. The hotel receives feedback
+ from guests in various languages in the form of physical comment cards. That feedback
+ is uploaded into the app through a web client.
+
+ After an image of a comment card is uploaded, the following steps occur:
+
+
+
+ Text is extracted from the image using &TEXTRACT;.
+
+
+ &CMP; determines the sentiment of the extracted text and its language.
+
+
+ The extracted text is translated to French using &TSL;.
+
+
+ &POL; synthesizes an audio file from the extracted text.
+
+
+ The full app can be deployed with the &CDK;. For source code and deployment
+ instructions, see the project in
+ GitHub.
+
\ No newline at end of file
diff --git a/.doc_gen/metadata/cross_metadata.yaml b/.doc_gen/metadata/cross_metadata.yaml
index da78e464480..87d447c5160 100644
--- a/.doc_gen/metadata/cross_metadata.yaml
+++ b/.doc_gen/metadata/cross_metadata.yaml
@@ -6,6 +6,10 @@ cross_FSA:
their original language, determines their sentiment, and generates an audio file
from the translated text.
languages:
+ Java:
+ versions:
+ - sdk_version: 2
+ block_content: cross_FSA_Java_block.xml
Ruby:
versions:
- sdk_version: 3
diff --git a/.github/pre_validate/pre_validate.py b/.github/pre_validate/pre_validate.py
index 3357d7bacec..f7d79ff6e2b 100644
--- a/.github/pre_validate/pre_validate.py
+++ b/.github/pre_validate/pre_validate.py
@@ -103,6 +103,7 @@
'AKIAIOSFODNN7EXAMPLE',
'APKAEIBAERJR2EXAMPLE',
'AppStreamUsageReportsCFNGlueAthenaAccess',
+ 'examples/blob/main/applications/feedback',
'aws/acm/model/DescribeCertificateRequest',
'aws/cloudtrail/model/LookupEventsRequest',
'aws/codebuild/model/BatchGetBuildsResult',
diff --git a/applications/feedback_sentiment_analyzer/README.md b/applications/feedback_sentiment_analyzer/README.md
index 04c30745163..78e0c3ae171 100644
--- a/applications/feedback_sentiment_analyzer/README.md
+++ b/applications/feedback_sentiment_analyzer/README.md
@@ -16,6 +16,7 @@ This application has been implemented with the following AWS SDKs.
- [Ruby](../../ruby/cross_service_examples/feedback_sentiment_analyzer/README.md)
- [JavaScript](../../javascriptv3/example_code/cross-services/feedback-sentiment-analyzer/README.md)
+- [Java](../../javav2/usecases/creating_fsa_app/README.md)
To deploy one of these implementations, follow the [Deployment instructions](#deployment-instructions).
diff --git a/applications/feedback_sentiment_analyzer/cdk/lib/functions.ts b/applications/feedback_sentiment_analyzer/cdk/lib/functions.ts
index 21c9cd18b6d..77bd6a54cf4 100644
--- a/applications/feedback_sentiment_analyzer/cdk/lib/functions.ts
+++ b/applications/feedback_sentiment_analyzer/cdk/lib/functions.ts
@@ -6,7 +6,6 @@
import {resolve} from "path";
import {BundlingOutput, Duration} from "aws-cdk-lib";
import {Code, Runtime} from "aws-cdk-lib/aws-lambda";
-
import {AppFunctionConfig} from "./constructs/app-lambdas";
const BASE_APP_FUNCTION: AppFunctionConfig = {
@@ -55,7 +54,7 @@ const EXAMPLE_LANG_FUNCTIONS: AppFunctionConfig[] = [
return Code.fromInline(`
exports.handler = async (event) => {
console.log("AnalyzeSentiment", event);
- return { translated_text: "Bonjour", source_language: "en" }
+ return { translated_text: "Bonjour", source_language: "en"}
}
`);
},
@@ -164,14 +163,63 @@ const JAVASCRIPT_FUNCTIONS = [
},
];
+const JAVA_BUNDLING_CONFIG = {
+ command: [
+ "bash",
+ "-c",
+ "mvn install -DskipTests && cp target/creating_fsa_app-1.0-SNAPSHOT.jar /asset-output/",
+ ],
+ output: BundlingOutput.ARCHIVED,
+ user: "root",
+ image: Runtime.JAVA_11.bundlingImage,
+ volumes: [
+ {
+ hostPath: `${process.env.HOME}/.m2/`,
+ containerPath: "/root/.m2",
+ },
+ ],
+};
+
+const COMMON_JAVA_FUNCTION_CONFIG = {
+ ...BASE_APP_FUNCTION,
+ runtime: Runtime.JAVA_11,
+ codeAsset: () => {
+ const source = resolve("../../../javav2/usecases/creating_fsa_app");
+ return Code.fromAsset(source, {
+ bundling: JAVA_BUNDLING_CONFIG,
+ });
+ },
+};
+
+const JAVA_FUNCTIONS: AppFunctionConfig[] = [
+ {
+ ...COMMON_JAVA_FUNCTION_CONFIG,
+ name: "ExtractText",
+ handler: "com.example.fsa.handlers.ExtractTextHandler::handleRequest",
+ },
+ {
+ ...COMMON_JAVA_FUNCTION_CONFIG,
+ name: "AnalyzeSentiment",
+ handler: "com.example.fsa.handlers.AnalyzeSentimentHandler::handleRequest",
+ },
+ {
+ ...COMMON_JAVA_FUNCTION_CONFIG,
+ name: "TranslateText",
+ handler: "com.example.fsa.handlers.TranslateTextHandler::handleRequest",
+ },
+ {
+ ...COMMON_JAVA_FUNCTION_CONFIG,
+ name: "SynthesizeAudio",
+ handler: "com.example.fsa.handlers.SynthesizeAudioHandler::handleRequest",
+ },
+];
+
const FUNCTIONS: Record = {
examplelang: EXAMPLE_LANG_FUNCTIONS,
- // Add more languages here. For example
- // javascript: JAVASCRIPT_FUNCTIONS,
ruby: RUBY_FUNCTIONS,
+ java: JAVA_FUNCTIONS,
javascript: JAVASCRIPT_FUNCTIONS,
};
-
export function getFunctions(language: string = ""): AppFunctionConfig[] {
return FUNCTIONS[language] ?? FUNCTIONS.examplelang;
}
diff --git a/javav2/README.md b/javav2/README.md
index ee1cccab5ab..42efadcf472 100644
--- a/javav2/README.md
+++ b/javav2/README.md
@@ -25,7 +25,9 @@ The **javav2** folder in this repository contains examples of complete use cases
In the **use_cases** folder, find step-by-step development tutorials that use multiple AWS services. By following these tutorials, you will gain a deeper understanding of how to create Java-based applications that use the AWS SDK for Java. Most of these AWS SDK for Java tutorials use the Synchronous Java client.
-If you are interested in using the Asynchronous Java client, see one of these tutorials:
+If you are interested in using Asynchronous Java service clients, see one of these tutorials:
+
++ [Creating a Feedback Sentiment Analyzer application using the SDK for Java](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/usecases/creating_fsa_app) - Discusses how to develop a Feedback Sentiment Analyzer application using Machine Learning AWS services. The application solves a fictitious use case of a hotel that receives guest feedback on comment cards in a variety of languages. The application is developed by using the AWS SDK for Java (v2) and asynchronous Java clients.
+ [Creating a dynamic web application that asynchronously analyzes photos using the AWS SDK for Java](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/usecases/creating_photo_analyzer_async) - Discusses using the AWS SDK for Java (asynchronous client) and various AWS services, such as the Amazon Rekognition service, to analyze images. This web MVC application can analyze many images and generate a report that breaks down each image into a series of labels.
diff --git a/javav2/usecases/creating_fsa_app/README.md b/javav2/usecases/creating_fsa_app/README.md
new file mode 100644
index 00000000000..1911f49a5d2
--- /dev/null
+++ b/javav2/usecases/creating_fsa_app/README.md
@@ -0,0 +1,846 @@
+# Creating a Feedback Sentiment Analyzer application using the SDK for Java
+
+## Overview
+
+| Heading | Description |
+| ----------- | ----------- |
+| Description | Discusses how to develop a Feedback Sentiment Analyzer application using [Machine Learning AWS services](https://aws.amazon.com/machine-learning/). The application solves a fictitious use case of a hotel that receives guest feedback on comment cards in a variety of languages. The application is developed by using the AWS SDK for Java (v2) and asynchronous service clients. For information, see [Asynchronous programming](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/asynchronous.html). |
+| Audience | Developer (intermediate / advanced) |
+| Updated | 9/12/2023 |
+| Required skills | Java, Maven |
+
+## Purpose
+
+You can develop a sample application for a Feedback Sentiment Analyzer (FSA) that accomplishes the following tasks:
+
+1. Hosts static website assets in an Amazon Simple Storage Service (Amazon S3) bucket, and uses an Amazon CloudFront distribution to serve the website.
+2. Implements authenticated access to Amazon API Gateway through Amazon Cognito.
+3. Configures Amazon API Gateway to deposit items into an S3 bucket, subsequently triggering an Amazon EventBridge rule that initiates an AWS Step Functions workflow.
+4. The Step Functions workflow leverages AWS Lambda, Amazon Textract, Amazon Comprehend, Amazon Translate, and Amazon Polly to execute the core business logic.
+5. Metadata gets stored within Amazon DynamoDB, while audio files are stored in the same S3 bucket referenced in step 3.
+6. Amazon API Gateway retrieves the metadata from Amazon DynamoDB.
+
+
+![AWS Photo Analyzer](images/overview.png)
+
+As displayed in the preceding illustration, the FSA application uses the following AWS services:
+
+* Amazon Textract - Extracts text
+* Amazon Comprehend - Detects sentiment
+* Amazon Translate - Translates to English
+* Amazon Polly - Synthesizes to human-like speech
+
+#### Topics
+
++ Prerequisites
++ Understand the Feedback Sentiment Analyzer application
++ Create an IntelliJ project
++ Add the POM dependencies to your project
++ Create the Java classes
++ Deploy the AWS resources
+
+## Prerequisites
+
+To complete the tutorial, you need the following:
+
++ An AWS account
++ A Java IDE (this tutorial uses the IntelliJ IDE)
++ Java JDK 11
++ Maven 3.6 or later
+
+### Important
+
++ The AWS services included in this document are included in the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc).
++ This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
++ Running this code might result in charges to your AWS account.
++ Be sure to delete all of the resources you create while going through this tutorial so that you won't be charged.
++ Also make sure to properly set up your development environment. For information, see [Setting up the AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup.html).
+
+### Resource creation
+
+The required AWS resources are created by using an AWS Cloud Development Kit (AWS CDK) script. This is discussed later in the document. There is no need to create any resources by using the AWS Management Console.
+
+## Understand the Feedback Sentiment Analyzer application
+
+The front end of the FSA application is a React application that uses the [Cloudscape Design System](https://cloudscape.design/). The application supports uploading images that contain text to an S3 bucket. The text represents comments made by a customer in various languages, such as French.
+
+After a user authenticates by using Amazon Cognito, the application displays all uploaded images, the translated text, and a button that lets the user hear the audio (which was created by using Amazon Polly).
+
+![AWS Photo Analyzer](images/app.png)
+
+### What happens after an image is uploaded to an S3 bucket
+
+After an image is uploaded into the storage bucket, an EventBridge rule is triggered that starts a Step Functions workflow.
+
+![AWS Photo Analyzer](images/workflow.png)
+
+The following descibes each step in the workflow.
+
+- **ExtractText** - Extracts text from the image. The text can be in another language such as French.
+- **AnalyzeSentiment** - Retrieves the sentiment of the text. For example, it can determine if the text is positive or negative.
+- **ContinueIfPositive** - Routes the workflow based on the sentiment value. If the value is positive, the the next step is TranslateText.
+- **TranslateText** - Translates the text into English.
+- **SynthesizeAudio** - Converts the English text into an MP3 audio file and places the audio file into an S3 bucket.
+- **PutPositiveComment** - Places the data into an Amazon DynamoDB table.
+
+**Note**: The client React application does not display any data until the workflow successfully completes and data is stored in the S3 bucket and DynamoDB table.
+
+The following illustration shows the Amazon DynamoDB table storing the values.
+
+![AWS Photo Analyzer](images/dbtable.png)
+
+**Note**: This DynamoDB table is created when you run the AWS CDK script to set up the resources. This is discussed later in this document.
+
+### Understand the AWS resources used by the FSA application
+
+This section describes the AWS resources that the FSA application uses. You do not have to manually deploy any of these AWS resources, such as the AWS Lambda functions, by using the AWS Management Console. Instead, you can deploy all of them by running a provided AWS CDK script. Instructions on how to deploy these AWS resources are provided later in this document.
+
+#### AWS Lambda functions
+
+The backend of the FSA application is implemented by using these AWS Lambda functions created by using the AWS SDK for Java (v2):
+
+- **ExtractText**
+- **AnalyzeSentiment**
+- **TranslateText**
+- **SynthesizeAudio**
+
+**Note**: These AWS Lambda names are short names. The full names that appear in the AWS Management Console depend on how you configure the provided AWS CDK script. Full names appear as {NAME}{Function Name}. For example, **fsa-user-java-SynthesizeAudio134971D4-x8Q5178Y4ZBH**.
+
+## Create an IntelliJ project
+
+1. In the IntelliJ IDE, choose **File**, **New**, **Project**.
+2. In the **New Project** dialog box, choose **Maven**, and then choose **Next**.
+3. For **GroupId**, enter **aws-fsa**.
+4. For **ArtifactId**, enter **fsa_app**.
+6. Choose **Next**.
+7. Choose **Finish**.
+
+## Add the POM dependencies to your project
+
+At this point, you have a new project named **fsa_app**.
+
+**Note:** Be sure to use Java 11 (as shown in the following **pom.xml** file).
+
+Make sure that the **pom.xml** file looks like the following.
+
+```xml
+
+
+ 4.0.0
+ org.example
+ creating_fsa_app
+ 1.0-SNAPSHOT
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+ software.amazon.awssdk
+ bom
+ 2.20.45
+ pom
+ import
+
+
+ org.apache.logging.log4j
+ log4j-bom
+ 2.19.0
+ pom
+ import
+
+
+
+
+
+ software.amazon.awssdk
+ dynamodb
+
+
+ commons-logging
+ commons-logging
+ 1.2
+
+
+ software.amazon.awssdk
+ apache-client
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ software.amazon.awssdk
+ s3
+
+
+ software.amazon.awssdk.crt
+ aws-crt
+ 0.25.1
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+ org.apache.logging.log4j
+ log4j-slf4j2-impl
+
+
+ org.apache.logging.log4j
+ log4j-1.2-api
+
+
+ com.amazonaws
+ aws-lambda-java-events
+ 3.11.1
+
+
+ software.amazon.awssdk
+ textract
+
+
+ software.amazon.awssdk
+ s3control
+
+
+ com.amazonaws
+ aws-lambda-java-core
+ 1.2.2
+
+
+ software.amazon.awssdk
+ translate
+
+
+ software.amazon.awssdk
+ comprehend
+
+
+ org.json
+ json
+ 20230227
+
+
+ software.amazon.awssdk
+ polly
+
+
+ org.apache.maven.surefire
+ surefire-booter
+ 3.0.0-M3
+
+
+ software.amazon.awssdk
+ lambda
+
+
+ commons-io
+ commons-io
+ 2.7
+
+
+ software.amazon.awssdk
+ s3-transfer-manager
+ 2.20.26
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.9.0
+ test
+
+
+ com.googlecode.json-simple
+ json-simple
+ 1.1
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.9.0
+ test
+
+
+
+
+
+ maven-surefire-plugin
+ 2.22.2
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.3.0
+
+ false
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+```
+
+## Create the Java classes
+
+Create a Java package in the **main/java** folder named **com.example.fsa**. The Java files go into sub-packages.
+
+### Handlers package
+
+Create these Java classes in the **com.example.fsa.handlers** package. These Java classes use the AWS Lambda Java runtime API to build the AWS Lambda functions described earlier in this document. Each class represents a handler for a separate AWS Lambda function. For more information about the AWS Lambda Java runtime API, see [AWS Lambda function handler in Java](https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html).
+
++ **AnalyzeSentimentHandler** - The handler for the **AnalyzeSentiment** Lambda function.
++ **ExtractTextHandler** - The handler for the **ExtractText** Lambda function.
++ **SynthesizeAudioHandler** - The handler for the **fnSynthesizeAudio** Lambda function.
++ **TranslateTextHandler** - The handler for the **TranslateText** Lambda function.
+
+#### AnalyzeSentimentHandler class
+
+The following is the **AnalyzeSentimentHandler** class.
+
+```java
+package com.example.fsa.handlers;
+
+import com.amazonaws.services.lambda.runtime.Context;
+import com.amazonaws.services.lambda.runtime.RequestHandler;
+import com.example.fsa.services.DetectSentimentService;
+import org.json.simple.JSONObject;
+import java.util.Map;
+
+public class AnalyzeSentimentHandler implements RequestHandler