Skip to content

Commit 38d17e5

Browse files
committed
First iteration of aws-lambda-transcribe
1 parent defc8fd commit 38d17e5

33 files changed

+7460
-1
lines changed

source/package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
*.js
2+
*.js.map
3+
*.d.ts
4+
node_modules
5+
*.generated.ts
6+
dist
7+
.jsii
8+
9+
.nyc_output
10+
coverage
11+
.nycrc
12+
.LAST_BUILD
13+
.nyc_output
14+
junit.xml
15+
test-reports/
16+
!jest.config.js
17+
*.tsbuildinfo
18+
19+
.LAST_PACKAGE
20+
*.snk
21+
nyc.config.js
22+
!.eslintrc.js
23+
!jest.config.js
24+
25+
# CDK asset staging directory
26+
.cdk.staging
27+
cdk.out
28+
29+
# Parcel default cache directory
30+
.parcel-cache
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# The basics
2+
*.ts
3+
*.tsx
4+
!*.d.ts
5+
!*.js
6+
*.map
7+
.jsii
8+
.nyc_output
9+
coverage
10+
node_modules
11+
*.tgz
12+
*.snk
13+
tsconfig.json
14+
.eslintrc.js
15+
# Runtime dependencies (we bundle them)
16+
/node_modules/
17+
18+
# Test .js files
19+
test/
20+
!*.d.ts
21+
*.tsbuildinfo
22+
23+
# exclude cdk artifacts
24+
**/cdk.out
25+
junit.xml
26+
test-reports/
27+
28+
29+
# Exclude jsii outdir
30+
dist
31+
32+
# Include .jsii and .jsii.gz
33+
!.jsii
34+
!.jsii.gz
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
//!!NODE_ROOT <section>
2+
//== aws-lambda-transcribe module
3+
4+
[.topic]
5+
= aws-lambda-transcribe
6+
:info_doctype: section
7+
:info_title: aws-lambda-transcribe
8+
9+
10+
image:https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge[Stability:Experimental]
11+
12+
[width="100%",cols="<50%,<50%",options="header",]
13+
|===
14+
|*Reference Documentation*:
15+
|https://docs.aws.amazon.com/solutions/latest/constructs/
16+
|===
17+
18+
[width="100%",cols="<46%,54%",options="header",]
19+
|===
20+
|*Language* |*Package*
21+
|image:https://docs.aws.amazon.com/cdk/api/latest/img/python32.png[Python
22+
Logo] Python |`aws_solutions_constructs.aws_lambda_transcribe`
23+
24+
|image:https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png[Typescript
25+
Logo] Typescript |`@aws-solutions-constructs/aws-lambda-transcribe`
26+
27+
|image:https://docs.aws.amazon.com/cdk/api/latest/img/java32.png[Java
28+
Logo] Java |`software.amazon.awsconstructs.services.lambdatranscribe`
29+
|===
30+
31+
== Overview
32+
33+
This AWS Solutions Construct implements an AWS Lambda function connected
34+
to Amazon S3 buckets for use with Amazon Transcribe. The construct creates
35+
a source bucket for audio files and a destination bucket for transcription
36+
results, with appropriate IAM permissions for the Lambda function to interact
37+
with both buckets and Amazon Transcribe service.
38+
39+
Here is a minimal deployable pattern definition:
40+
41+
====
42+
[role="tablist"]
43+
Typescript::
44+
+
45+
[source,typescript]
46+
----
47+
import { Construct } from 'constructs';
48+
import { Stack, StackProps } from 'aws-cdk-lib';
49+
import { LambdaToTranscribe } from '@aws-solutions-constructs/aws-lambda-transcribe';
50+
import * as lambda from 'aws-cdk-lib/aws-lambda';
51+
52+
new LambdaToTranscribe(this, 'LambdaToTranscribePattern', {
53+
lambdaFunctionProps: {
54+
runtime: lambda.Runtime.NODEJS_20_X,
55+
handler: 'index.handler',
56+
code: lambda.Code.fromAsset(`lambda`)
57+
}
58+
});
59+
----
60+
61+
Python::
62+
+
63+
[source,python]
64+
----
65+
from aws_solutions_constructs.aws_lambda_transcribe import LambdaToTranscribe
66+
from aws_cdk import (
67+
aws_lambda as _lambda,
68+
Stack
69+
)
70+
from constructs import Construct
71+
72+
LambdaToTranscribe(self, 'LambdaToTranscribePattern',
73+
lambda_function_props=_lambda.FunctionProps(
74+
code=_lambda.Code.from_asset('lambda'),
75+
runtime=_lambda.Runtime.PYTHON_3_11,
76+
handler='index.handler'
77+
)
78+
)
79+
----
80+
81+
Java::
82+
+
83+
[source,java]
84+
----
85+
import software.constructs.Construct;
86+
87+
import software.amazon.awscdk.Stack;
88+
import software.amazon.awscdk.StackProps;
89+
import software.amazon.awscdk.services.lambda.*;
90+
import software.amazon.awscdk.services.lambda.Runtime;
91+
import software.amazon.awsconstructs.services.lambdatranscribe.*;
92+
93+
new LambdaToTranscribe(this, "LambdaToTranscribePattern", new LambdaToTranscribeProps.Builder()
94+
.lambdaFunctionProps(new FunctionProps.Builder()
95+
.runtime(Runtime.NODEJS_20_X)
96+
.code(Code.fromAsset("lambda"))
97+
.handler("index.handler")
98+
.build())
99+
.build());
100+
----
101+
====
102+
103+
== Pattern Construct Props
104+
105+
[width="100%",cols="<30%,<35%,35%",options="header",]
106+
|===
107+
|*Name* |*Type* |*Description*
108+
|existingLambdaObj?
109+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html[`lambda.Function`]
110+
|Existing instance of Lambda Function object, providing both this and
111+
`lambdaFunctionProps` will cause an error.
112+
113+
|lambdaFunctionProps?
114+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.FunctionProps.html[`lambda.FunctionProps`]
115+
|Optional user provided props to override the default props for the
116+
Lambda function.
117+
118+
|existingSourceBucketObj?
119+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html[`s3.IBucket`]
120+
|Existing instance of S3 Bucket object for source audio files. If this is provided, then also
121+
providing sourceBucketProps is an error.
122+
123+
|sourceBucketProps?
124+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html[`s3.BucketProps`]
125+
|Optional user provided props to override the default props for the source S3
126+
Bucket.
127+
128+
|existingDestinationBucketObj?
129+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html[`s3.IBucket`]
130+
|Existing instance of S3 Bucket object for transcription results. If this is provided, then also
131+
providing destinationBucketProps is an error.
132+
133+
|destinationBucketProps?
134+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html[`s3.BucketProps`]
135+
|Optional user provided props to override the default props for the destination S3
136+
Bucket.
137+
138+
|useSameBucket? |`boolean` |Whether to use the same S3 bucket for both source and destination files.
139+
When true, only the source bucket will be created and used for both purposes. Default: false
140+
141+
|existingVpc?
142+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html[`ec2.IVpc`]
143+
|An optional, existing VPC into which this pattern should be deployed.
144+
When deployed in a VPC, the Lambda function will use ENIs in the VPC to
145+
access network resources and Interface Endpoints will be created in
146+
the VPC for Amazon S3 and Amazon Transcribe. If an existing VPC is provided, the `deployVpc`
147+
property cannot be `true`. This uses `ec2.IVpc` to allow clients to
148+
supply VPCs that exist outside the stack using the
149+
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Vpc.html#static-fromwbrlookupscope-id-options[`ec2.Vpc.fromLookup()`]
150+
method.
151+
152+
|vpcProps?
153+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.VpcProps.html[`ec2.VpcProps`]
154+
|Optional user provided properties to override the default properties
155+
for the new VPC. `enableDnsHostnames`, `enableDnsSupport`, `natGateways`
156+
and `subnetConfiguration` are set by the pattern, so any values for
157+
those properties supplied here will be overridden. If `deployVpc` is not
158+
`true` then this property will be ignored.
159+
160+
|deployVpc? |`boolean` |Whether to create a new VPC based on `vpcProps`
161+
into which to deploy this pattern. Setting this to true will deploy the
162+
minimal, most private VPC to run the pattern.
163+
164+
|sourceBucketEnvironmentVariableName? |`string` |Optional Name for the Lambda
165+
function environment variable set to the name of the source bucket. Default:
166+
SOURCE_BUCKET_NAME
167+
168+
|destinationBucketEnvironmentVariableName? |`string` |Optional Name for the Lambda
169+
function environment variable set to the name of the destination bucket. Default:
170+
DESTINATION_BUCKET_NAME
171+
172+
|sourceLoggingBucketProps?
173+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html[`s3.BucketProps`]
174+
|Optional user provided props to override the default props for the source S3
175+
Logging Bucket.
176+
177+
|destinationLoggingBucketProps?
178+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html[`s3.BucketProps`]
179+
|Optional user provided props to override the default props for the destination S3
180+
Logging Bucket.
181+
182+
|logSourceS3AccessLogs? |boolean |Whether to turn on Access Logging for the source S3
183+
bucket. Creates an S3 bucket with associated storage costs for the logs.
184+
Enabling Access Logging is a best practice. default - true
185+
186+
|logDestinationS3AccessLogs? |boolean |Whether to turn on Access Logging for the destination S3
187+
bucket. Creates an S3 bucket with associated storage costs for the logs.
188+
Enabling Access Logging is a best practice. default - true
189+
|===
190+
191+
== Pattern Properties
192+
193+
[width="100%",cols="<30%,<35%,35%",options="header",]
194+
|===
195+
|*Name* |*Type* |*Description*
196+
|lambdaFunction
197+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html[`lambda.Function`]
198+
|Returns an instance of the Lambda function created by the pattern.
199+
200+
|sourceBucket?
201+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html[`s3.Bucket`]
202+
|Returns an instance of the source S3 bucket if it is created by the pattern.
203+
204+
|destinationBucket?
205+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html[`s3.Bucket`]
206+
|Returns an instance of the destination S3 bucket if it is created by the pattern.
207+
208+
|sourceLoggingBucket?
209+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html[`s3.Bucket`]
210+
|Returns an instance of s3.Bucket created by the construct as the
211+
logging bucket for the source bucket.
212+
213+
|destinationLoggingBucket?
214+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html[`s3.Bucket`]
215+
|Returns an instance of s3.Bucket created by the construct as the
216+
logging bucket for the destination bucket.
217+
218+
|vpc?
219+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html[`ec2.IVpc`]
220+
|Returns an interface on the VPC used by the pattern (if any). This may
221+
be a VPC created by the pattern or the VPC supplied to the pattern
222+
constructor.
223+
224+
|sourceBucketInterface
225+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html[`s3.IBucket`]
226+
|Returns an interface of s3.IBucket used by the construct for the source bucket whether created by the pattern or supplied from the client.
227+
228+
|destinationBucketInterface
229+
|https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html[`s3.IBucket`]
230+
|Returns an interface of s3.IBucket used by the construct for the destination bucket whether created by the pattern or supplied from the client.
231+
|===
232+
233+
== Default settings
234+
235+
Out of the box implementation of the Construct without any override will
236+
set the following defaults:
237+
238+
=== AWS Lambda Function
239+
240+
* Configure limited privilege access IAM role for Lambda function
241+
* Enable reusing connections with Keep-Alive for NodeJs Lambda function
242+
* Enable X-Ray Tracing
243+
* Set Environment Variables
244+
** (default) SOURCE_BUCKET_NAME
245+
** (default) DESTINATION_BUCKET_NAME
246+
** AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x
247+
and higher functions)
248+
* Grant permissions to use Amazon Transcribe service, write permissions to the source bucket, and read permissions to the destination bucket
249+
250+
=== Amazon S3 Buckets
251+
252+
* Configure Access logging for both S3 Buckets
253+
* Enable server-side encryption for both S3 Buckets using AWS managed KMS Key
254+
* Enforce encryption of data in transit
255+
* Turn on the versioning for both S3 Buckets
256+
* Don't allow public access for both S3 Buckets
257+
* Retain the S3 Buckets when deleting the CloudFormation stack
258+
* Applies Lifecycle rule to move noncurrent object versions to Glacier
259+
storage after 90 days
260+
261+
=== Amazon Transcribe Service
262+
263+
* The Transcribe service will have read access to the source bucket and write permissions to the destination bucket
264+
* Lambda function will have permissions to start transcription jobs, get job status, and list transcription jobs
265+
266+
=== Amazon VPC
267+
268+
* If deployVpc is true, a minimal VPC will be created with:
269+
** Interface Endpoints for Amazon S3 and Amazon Transcribe
270+
** Private subnets for Lambda function
271+
** Appropriate security groups and routing
272+
273+
== Architecture
274+
275+
276+
image::aws-lambda-transcribe.png["Diagram showing the Lambda function, source and destination S3 buckets, Amazon Transcribe service, and IAM roles created by the construct",scaledwidth=100%]
277+
278+
== Example Lambda Function Implementation
279+
280+
While Solutions Constructs does not publish code for the Lambda function to call Transcribe, there is an example of calling Transcribe https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/transcribe/src/transcribe_create_job.js['here'].
281+
282+
// github block
283+
284+
'''''
285+
286+
© Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

0 commit comments

Comments
 (0)