aws-lambda-polly
| Reference Documentation: | https://docs.aws.amazon.com/solutions/latest/constructs/ |
| Language | Package |
|---|---|
|
|
|
|
|
|
|
|
|
Overview
This AWS Solutions Construct implements an AWS Lambda function connected to Amazon Polly text-to-speech service. For asynchronous speech synthesis tasks, the construct can optionally create an S3 bucket for audio output and an SNS topic for completion notifications, with appropriate IAM permissions for the Lambda function to interact with Amazon Polly service.
Here is a minimal deployable pattern definition:
Example
Pattern Construct Props
| Name | Type | Description |
|---|---|---|
|
existingLambdaObj? |
Optional - instance of an existing Lambda Function object, providing both this and
|
|
|
lambdaFunctionProps? |
Optional - user provided props to override the default props for the Lambda function. Providing both this and |
|
|
asyncJobs? |
|
Whether to enable asynchronous speech synthesis tasks. When true, an S3 bucket for audio output and an SNS topic for completion notifications will be created, and the Lambda function will be granted permissions to start and monitor asynchronous synthesis tasks. Default: false |
|
existingBucketObj? |
Existing instance of S3 Bucket object for audio output, providing both this and |
|
|
bucketProps? |
Optional user provided props to override the default props for the S3 Bucket. Only valid when asyncJobs is true. |
|
|
bucketEnvironmentVariableName? |
|
Optional Name for the Lambda function environment variable set to the name of the output bucket. Only valid when asyncJobs is true. Default: OUTPUT_BUCKET_NAME |
|
logS3AccessLogs? |
|
Whether to turn on Access Logs for the S3 bucket with the associated storage costs. Enabling Access Logging is a best practice. Only valid when asyncJobs is true. Default: true |
|
loggingBucketProps? |
Optional user provided props to override the default props for the S3 Logging Bucket. Only valid when asyncJobs is true. |
|
|
existingTopicObj? |
Optional - existing instance of SNS topic object, providing both this and |
|
|
topicProps? |
Optional - user provided properties to override the default properties for the SNS topic.
Providing both this and |
|
|
topicEnvironmentVariableName? |
|
Optional Name for the Lambda function environment variable set to the ARN of the SNS topic used for asynchronous task completion notifications. Only valid when asyncJobs is true. Default: SNS_TOPIC_ARN |
|
existingTopicEncryptionKey? |
If an existing topic is provided in the |
|
|
topicEncryptionKey? |
An optional, imported encryption key to encrypt the SNS Topic with. Only valid when asyncJobs is true. |
|
|
topicEncryptionKeyProps? |
Optional user provided properties to override the default properties for the KMS encryption key used to encrypt the SNS Topic with. Only valid when asyncJobs is true. |
|
|
enableTopicEncryptionWithCustomerManagedKey? |
|
If no key is provided, this flag determines whether the SNS Topic is encrypted with a new CMK or an AWS managed key. This flag is ignored if any of the following are defined: topicProps.masterKey, topicEncryptionKey or topicEncryptionKeyProps. Only valid when asyncJobs is true. |
|
existingVpc? |
An existing VPC for the construct to use (construct will NOT create a new VPC in this case) |
|
|
vpcProps? |
Properties to override default properties if deployVpc is true |
|
|
deployVpc? |
|
Whether to deploy a new VPC. Default: false |
Pattern Properties
| Name | Type | Description |
|---|---|---|
|
lambdaFunction |
Returns an instance of the Lambda function created by the pattern. |
|
|
destinationBucket? |
Returns an instance of the S3 bucket if it is created by the pattern. |
|
|
loggingBucket? |
Returns an instance of s3.Bucket created by the construct as the logging bucket for the destination bucket. |
|
|
destinationBucketInterface? |
Returns an interface of s3.IBucket used by the construct for the destination bucket whether created by the pattern or supplied from the client. |
|
|
snsNotificationTopic? |
Returns an instance of the SNS topic created for asynchronous task completion notifications when asyncJobs is true. |
|
|
notificationTopicEncryptionKey? |
Returns an instance of kms.IKey used for the SNS Topic. |
|
|
vpc? |
Returns an interface on the VPC used by the pattern (if any). This may be a VPC created by the pattern or the VPC supplied to the pattern constructor. |
Default settings
Out of the box implementation of the Construct without any override will set the following defaults:
AWS Lambda Function
-
Configure limited privilege access IAM role for Lambda function
-
Enable reusing connections with Keep-Alive for NodeJs Lambda function
-
Enable X-Ray Tracing
-
Set Environment Variables
-
(default) OUTPUT_BUCKET_NAME (when asyncJobs is true)
-
(default) SNS_TOPIC_ARN (when asyncJobs is true)
-
AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)
-
-
Grant permissions to use Amazon Polly service (['polly:SynthesizeSpeech'] by default)
-
When asyncJobs is true, grant permissions to start and monitor asynchronous synthesis tasks (['polly:StartSpeechSynthesisTask', 'polly:GetSpeechSynthesisTask', 'polly:ListSpeechSynthesisTasks']), and read/write to the S3 bucket
Amazon S3 Bucket (when asyncJobs is true)
-
Configure Access logging for S3 Bucket
-
Enable server-side encryption for S3 Bucket using AWS managed KMS Key
-
Enforce encryption of data in transit
-
Turn on the versioning for S3 Bucket
-
Don’t allow public access for S3 Bucket
-
Retain the S3 Bucket when deleting the CloudFormation stack
-
Applies Lifecycle rule to move noncurrent object versions to Glacier storage after 90 days
Amazon SNS Topic (when asyncJobs is true)
-
Configure server-side encryption using AWS managed KMS Key
-
Create topic for asynchronous task completion notifications
Amazon Polly Service
-
Lambda function will have permissions to call ['polly:SynthesizeSpeech'] operation
When asyncJobs is true
-
Lambda function will add permissions to call ['polly:StartSpeechSynthesisTask', 'polly:GetSpeechSynthesisTask', 'polly:ListSpeechSynthesisTasks']
-
When asyncJobs is true, an SNS topic will be created and the Lambda function is granted permission to call ['sns:Publish']
Amazon VPC
-
If deployVpc is true, a minimal VPC will be created with:
-
Interface Endpoints for Amazon Polly
-
Gateway Endpoints for Amazon S3 (when asyncJobs is true)
-
Private subnets for Lambda function
-
Appropriate security groups and routing
-
Architecture
Default Implementation
Default Implementation when asyncJobs = true
Example Lambda Function Implementation
While Solutions Constructs does not publish code for the Lambda function to call Polly, here are examples of calling Polly: examples
Github
Go to the Github repo