Skip to content

Commit e2403cb

Browse files
committed
update README for DDB "Learn the basics"
1 parent 6dd5e1d commit e2403cb

File tree

12 files changed

+198
-229
lines changed

12 files changed

+198
-229
lines changed

.doc_gen/metadata/dynamodb_metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ dynamodb_Scenario_GettingStartedMovies:
19601960
- sdk_version: 3
19611961
github: php/example_code/dynamodb
19621962
excerpts:
1963-
- description:
1963+
- description: Because this example uses supporting files, be sure to <ulink url="https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/php/README.md#prerequisites">read the guidance</ulink> in the PHP examples README.md file.
19641964
snippet_tags:
19651965
- php.example_code.dynamodb.basics.scenario
19661966
Python:

.doc_gen/metadata/transcribe-streaming_metadata.yaml

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ transcribe-streaming_StartMedicalStreamTranscription:
4242
- transcribe.java-medical-streaming-demo
4343
services:
4444
transcribe-streaming: {StartMedicalStreamTranscription}
45-
transcribe-streaming_Scenario_StreamEvents_File:
46-
title: Generate a transcription of a file using an &AWS; SDK
45+
transcribe-streaming_Scenario_StreamEvents:
46+
title: Generate a transcription of an audio stream using an &AWS; SDK
4747
title_abbrev: Transcribe an audio file
4848
synopsis: generate a transcription of a source audio file using &TSC; streaming.
4949
category: Scenarios
@@ -58,39 +58,5 @@ transcribe-streaming_Scenario_StreamEvents_File:
5858
snippet_tags:
5959
- swift.transcribe-streaming.all
6060
- swift.transcribe-streaming.transcribeerror
61-
Java:
62-
versions:
63-
- sdk_version: 2
64-
github: javav2/example_code/transcribe-streaming
65-
sdkguide:
66-
excerpts:
67-
- description:
68-
snippet_tags:
69-
- transcribe.java-streaming-demo-file.main
70-
C++:
71-
versions:
72-
- sdk_version: 1
73-
github: cpp/example_code/transcribe-streaming
74-
excerpts:
75-
- description:
76-
snippet_tags:
77-
- transcribe.cpp.stream_transcription_async.code
78-
services:
79-
transcribe-streaming: {StartStreamTranscription}
80-
transcribe-streaming_Scenario_StreamEvents_Microphone:
81-
title: Generate a transcription from a microphone using an &AWS; SDK
82-
title_abbrev: Transcribe audio from a microphone
83-
synopsis: generate a transcription from a microphone using &TSC; streaming.
84-
category: Scenarios
85-
languages:
86-
Java:
87-
versions:
88-
- sdk_version: 2
89-
github: javav2/example_code/transcribe-streaming
90-
sdkguide:
91-
excerpts:
92-
- description:
93-
snippet_tags:
94-
- transcribe.java-streaming-demo
9561
services:
9662
transcribe-streaming: {StartStreamTranscription}

cpp/example_code/transcribe-streaming/README.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ Code excerpts that show you how to call individual service functions.
4343

4444
- [StartStreamTranscription](get_transcript.cpp#L28)
4545

46-
### Scenarios
47-
48-
Code examples that show you how to accomplish a specific task by calling multiple
49-
functions within the same service.
50-
51-
- [Transcribe an audio file](get_transcript.cpp)
52-
5346

5447
<!--custom.examples.start-->
5548
<!--custom.examples.end-->
@@ -76,18 +69,6 @@ folder.
7669

7770

7871

79-
#### Transcribe an audio file
80-
81-
This example shows you how to generate a transcription of a source audio file using Amazon Transcribe streaming.
82-
83-
84-
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_File.start-->
85-
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_File.end-->
86-
87-
88-
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents_File.start-->
89-
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents_File.end-->
90-
9172
### Tests
9273

9374
⚠ Running tests might result in charges to your AWS account.
@@ -118,4 +99,4 @@ This example shows you how to generate a transcription of a source audio file us
11899

119100
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
120101

121-
SPDX-License-Identifier: Apache-2.0
102+
SPDX-License-Identifier: Apache-2.0

javav2/example_code/transcribe-streaming/README.md

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@ For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav
3434
Code excerpts that show you how to call individual service functions.
3535

3636
- [StartMedicalStreamTranscription](src/main/java/com/amazonaws/transcribestreaming/TranscribeMedicalStreamingDemoApp.java#L25)
37-
- [StartStreamTranscription](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java#L36)
38-
39-
### Scenarios
40-
41-
Code examples that show you how to accomplish a specific task by calling multiple
42-
functions within the same service.
43-
44-
- [Transcribe an audio file](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoFile.java)
45-
- [Transcribe audio from a microphone](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java)
37+
- [StartStreamTranscription](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java#L26)
4638

4739

4840
<!--custom.examples.start-->
@@ -58,30 +50,6 @@ functions within the same service.
5850

5951

6052

61-
#### Transcribe an audio file
62-
63-
This example shows you how to generate a transcription of a source audio file using Amazon Transcribe streaming.
64-
65-
66-
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_File.start-->
67-
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_File.end-->
68-
69-
70-
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents_File.start-->
71-
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents_File.end-->
72-
73-
#### Transcribe audio from a microphone
74-
75-
This example shows you how to generate a transcription from a microphone using Amazon Transcribe streaming.
76-
77-
78-
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_Microphone.start-->
79-
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_Microphone.end-->
80-
81-
82-
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents_Microphone.start-->
83-
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents_Microphone.end-->
84-
8553
### Tests
8654

8755
⚠ Running tests might result in charges to your AWS account.
@@ -108,4 +76,4 @@ in the `javav2` folder.
10876

10977
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
11078

111-
SPDX-License-Identifier: Apache-2.0
79+
SPDX-License-Identifier: Apache-2.0

javav2/example_code/transcribe-streaming/src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,8 @@
1212
import software.amazon.awssdk.regions.Region;
1313
import software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient;
1414
import software.amazon.awssdk.services.transcribestreaming.model.*;
15-
16-
import javax.sound.sampled.AudioFormat;
17-
import javax.sound.sampled.AudioInputStream;
18-
import javax.sound.sampled.AudioSystem;
19-
import javax.sound.sampled.DataLine;
20-
import javax.sound.sampled.LineUnavailableException;
21-
import javax.sound.sampled.TargetDataLine;
22-
import java.io.IOException;
23-
import java.io.InputStream;
24-
import java.io.PrintWriter;
25-
import java.io.StringWriter;
26-
import java.io.UncheckedIOException;
15+
import javax.sound.sampled.*;
16+
import java.io.*;
2717
import java.net.URISyntaxException;
2818
import java.nio.ByteBuffer;
2919
import java.util.List;
@@ -38,7 +28,7 @@ public class TranscribeStreamingDemoApp {
3828
private static final Region REGION = Region.US_EAST_1;
3929
private static TranscribeStreamingAsyncClient client;
4030

41-
public static void main(String[] args)
31+
public static void main(String args[])
4232
throws URISyntaxException, ExecutionException, InterruptedException, LineUnavailableException {
4333

4434
client = TranscribeStreamingAsyncClient.builder()
@@ -95,7 +85,7 @@ private static StartStreamTranscriptionResponseHandler getResponseHandler() {
9585
System.out.println(e.getMessage());
9686
StringWriter sw = new StringWriter();
9787
e.printStackTrace(new PrintWriter(sw));
98-
System.out.println("Error Occurred: " + sw);
88+
System.out.println("Error Occurred: " + sw.toString());
9989
})
10090
.onComplete(() -> {
10191
System.out.println("=== All records stream successfully ===");
@@ -111,10 +101,19 @@ private static StartStreamTranscriptionResponseHandler getResponseHandler() {
111101
.build();
112102
}
113103

114-
104+
private InputStream getStreamFromFile(String audioFileName) {
105+
try {
106+
File inputFile = new File(getClass().getClassLoader().getResource(audioFileName).getFile());
107+
InputStream audioStream = new FileInputStream(inputFile);
108+
return audioStream;
109+
} catch (FileNotFoundException e) {
110+
throw new RuntimeException(e);
111+
}
112+
}
113+
115114
private static class AudioStreamPublisher implements Publisher<AudioStream> {
116-
private static Subscription currentSubscription;
117115
private final InputStream inputStream;
116+
private static Subscription currentSubscription;
118117

119118
private AudioStreamPublisher(InputStream inputStream) {
120119
this.inputStream = inputStream;
@@ -123,22 +122,22 @@ private AudioStreamPublisher(InputStream inputStream) {
123122
@Override
124123
public void subscribe(Subscriber<? super AudioStream> s) {
125124

126-
if (currentSubscription == null) {
127-
currentSubscription = new SubscriptionImpl(s, inputStream);
125+
if (this.currentSubscription == null) {
126+
this.currentSubscription = new SubscriptionImpl(s, inputStream);
128127
} else {
129-
currentSubscription.cancel();
130-
currentSubscription = new SubscriptionImpl(s, inputStream);
128+
this.currentSubscription.cancel();
129+
this.currentSubscription = new SubscriptionImpl(s, inputStream);
131130
}
132131
s.onSubscribe(currentSubscription);
133132
}
134133
}
135134

136135
public static class SubscriptionImpl implements Subscription {
137-
private static final int CHUNK_SIZE_IN_BYTES = 1024;
136+
private static final int CHUNK_SIZE_IN_BYTES = 1024 * 1;
138137
private final Subscriber<? super AudioStream> subscriber;
139138
private final InputStream inputStream;
140-
private final ExecutorService executor = Executors.newFixedThreadPool(1);
141-
private final AtomicLong demand = new AtomicLong(0);
139+
private ExecutorService executor = Executors.newFixedThreadPool(1);
140+
private AtomicLong demand = new AtomicLong(0);
142141

143142
SubscriptionImpl(Subscriber<? super AudioStream> s, InputStream inputStream) {
144143
this.subscriber = s;

php/README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,75 @@ Cross-service examples are located in the [*cross-services folder*](cross_servic
2222
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
2323
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
2424

25+
## Prerequisites
2526

26-
### Prerequisites
27+
To run these code examples, you need:
28+
29+
* [PHP](https://www.php.net/) version 8.1 or higher
30+
* [Composer](https://getcomposer.org) for dependency management
31+
* [PHPUnit](https://phpunit.de/) for unit testing
32+
* The [AWS SDK for PHP](https://aws.amazon.com/sdk-for-php/)
33+
* [AWS credentials](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html) set up
34+
35+
For more information, see [Getting Started](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_index.html) in the AWS SDK for PHP Developer Guide.
36+
37+
## Set up the examples
38+
39+
Some examples require supporting files from the GitHub repository in addition to the AWS SDK for PHP. For these examples:
40+
41+
1. Clone, fork, or download the entire [aws-doc-sdk-examples repository](https://github.com/awsdocs/aws-doc-sdk-examples) from GitHub.
42+
43+
You need the entire repository, not just individual files, so supporting files can be accessed by the examples.
44+
45+
2. Install dependencies
46+
47+
From the directory that contains the composer.json file for the example, run:
48+
```bash
49+
composer install
50+
```
51+
52+
3. Run examples from within the repository structure and from the directory that contains the initiating code
53+
54+
Run examples from within the cloned directory structure to ensure access to supporting files.
55+
56+
## Run the examples
57+
58+
By default, these code examples run using the default AWS credential provider chain, which includes using the AWS shared credentials and config files with a `default` profile.
59+
For more information, about using AWS shared files and the `default` profile, see [Using shared config and credentials files to globally configure AWS SDKs and tools](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) in the *AWS SDKs and Tools
60+
Reference Guide*.
61+
62+
Important: Running these code examples might result in charges to the AWS account associated with the AWS credentials being used.
63+
64+
Many examples include a `Runner.php` file to abstract the logic from running the code. From any example directory with a Runner.php file, run:
65+
66+
```bash
67+
php Runner.php
68+
```
69+
70+
---------
71+
72+
## Prerequisites
2773
To run or test these code examples, you need the following:
2874

2975
- [PHP](https://www.php.net/) version 8.1 or higher
3076
- [Composer](https://getcomposer.org), for dependency management
3177
- [PHPUnit](https://phpunit.de/), for unit testing
3278
- The [AWS SDK for PHP](https://aws.amazon.com/sdk-for-php/)
3379
- [AWS credentials](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html) set up
80+
- For examples that use supporting files that are available only in the GitHub repository
81+
and not available for installation by Composer, you need to
82+
- clone, fork, or download a zip of the entire [aws-doc-sdk-examples repository](https://github.com/awsdocs/aws-doc-sdk-examples) from GitHub.
83+
You want the entire repository, not just indvidual files, so supporting files can be accessed by the examples.
84+
- Run the example from within the directory structure and from within the directory that contains the composer.json file.
85+
- Install the dependencies and configuration settings with Composer.
3486

3587
For more information, see [Getting Started](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_index.html) in the *AWS SDK for PHP Developer Guide*.
3688

3789
## Run the code
3890

39-
By default, these code examples run using the default AWS credential provider chain, which includes using an AWS shared credentials file and profiles.
40-
For more information, see [Using the AWS Credentials File and Credential Profiles](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_profiles.html) in the *AWS SDK for PHP Developer Guide*.
91+
By default, these code examples run using the default AWS credential provider chain, which includes using the AWS shared credentials and config files with a `default` profile.
92+
For more information, about using AWS shared files and the `default` profile, see [Using shared config and credentials files to globally configure AWS SDKs and tools](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) in the *AWS SDKs and Tools
93+
Reference Guide*.
4194

4295
Running these code examples might result in charges to the AWS account that is associated with the AWS credentials being used.
4396

php/example_code/dynamodb/DynamoDBService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class DynamoDBService extends AWSServiceClass
1717
public function __construct(
1818
DynamoDbClient $client = null,
1919
string $region = 'us-west-2',
20-
string $version = 'latest',
21-
string $profile = 'default'
20+
string $version = 'latest'
2221
) {
2322
if (gettype($client) == DynamoDbClient::class) {
2423
$this->dynamoDbClient = $client;
@@ -27,7 +26,6 @@ public function __construct(
2726
$this->dynamoDbClient = new DynamoDbClient([
2827
'region' => $region,
2928
'version' => $version,
30-
'profile' => $profile,
3129
'http' => [
3230
'verify' => false,
3331
],

php/example_code/dynamodb/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ Code examples that show you how to perform the essential operations within a ser
4040

4141
Code excerpts that show you how to call individual service functions.
4242

43-
- [BatchExecuteStatement](DynamoDBService.php#L319)
44-
- [BatchWriteItem](DynamoDBService.php#L201)
43+
- [BatchExecuteStatement](DynamoDBService.php#L317)
44+
- [BatchWriteItem](DynamoDBService.php#L199)
4545
- [CreateTable](dynamodb_basics/GettingStartedWithDynamoDB.php#L52)
4646
- [DeleteItem](dynamodb_basics/GettingStartedWithDynamoDB.php#L148)
47-
- [DeleteTable](DynamoDBService.php#L84)
48-
- [ExecuteStatement](DynamoDBService.php#L263)
47+
- [DeleteTable](DynamoDBService.php#L82)
48+
- [ExecuteStatement](DynamoDBService.php#L261)
4949
- [GetItem](dynamodb_basics/GettingStartedWithDynamoDB.php#L131)
50-
- [ListTables](DynamoDBService.php#L64)
50+
- [ListTables](DynamoDBService.php#L62)
5151
- [PutItem](dynamodb_basics/GettingStartedWithDynamoDB.php#L67)
5252
- [Query](dynamodb_basics/GettingStartedWithDynamoDB.php#L158)
5353
- [Scan](dynamodb_basics/GettingStartedWithDynamoDB.php#L178)
@@ -164,4 +164,4 @@ in the `php` folder.
164164

165165
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
166166

167-
SPDX-License-Identifier: Apache-2.0
167+
SPDX-License-Identifier: Apache-2.0

php/example_code/dynamodb/dynamodb_basics/Runner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use DynamoDb\Basics\GettingStartedWithDynamoDB;
66

7-
include "vendor\autoload.php";
7+
include "vendor/autoload.php";
88

99
include "GettingStartedWithDynamoDB.php";
1010

php/example_code/dynamodb/dynamodb_basics/composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"guzzlehttp/guzzle": "^7.0"
55
},
66
"autoload": {
7-
"psr-0": {
8-
"": "*"
9-
},
7+
"files": [
8+
"../../aws_utilities/TestableReadline.php",
9+
"../../aws_utilities/LoadMovieData.php"
10+
],
1011
"psr-4": {
1112
"DynamoDb\\": "../../dynamodb/",
1213
"DynamoDb\\Basics\\": "../../dynamodb/dynamodb_basics",
1314
"AwsUtilities\\": "../../aws_utilities"
14-
},
15-
"files": ["../../aws_utilities/TestableReadline.php"]
15+
}
1616
}
1717
}

0 commit comments

Comments
 (0)