-
Notifications
You must be signed in to change notification settings - Fork 1k
apigw-lambda-sfn-transcribe-translate-polly-sam: Update runtime to nodejs22.x #2842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4f13fa6
4fc582f
175507b
861cdd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
const AWS = require('aws-sdk'); | ||
const stepfunctions = new AWS.StepFunctions(); | ||
const apig = new AWS.ApiGatewayManagementApi({ | ||
endpoint: process.env.APIG_ENDPOINT, | ||
const { SFNClient, StartSyncExecutionCommand } = require('@aws-sdk/client-sfn'); | ||
const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require('@aws-sdk/client-apigatewaymanagementapi'); | ||
const stepfunctions = new SFNClient({}); | ||
const apig = new ApiGatewayManagementApiClient({ | ||
endpoint: `https://${process.env.APIG_ENDPOINT}`, | ||
}); | ||
|
||
module.exports.handler = async (event, context) => { | ||
|
@@ -25,12 +26,11 @@ module.exports.handler = async (event, context) => { | |
stateMachineArn: process.env.statemachine_arn, | ||
input: body | ||
} | ||
let response = await stepfunctions.startSyncExecution(params).promise(); | ||
await apig | ||
.postToConnection({ | ||
let response = await stepfunctions.send(new StartSyncExecutionCommand(params)); | ||
await apig.send(new PostToConnectionCommand({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Some error occurs. Because in Node.js 18 and later runtimes, AWS SDK v3 is bundled, so I rewrote it to v3. See articles below. |
||
ConnectionId: connectionId, | ||
Data: response?JSON.stringify( {"url" : JSON.parse(response.output).url} ):"No data" | ||
}).promise(); | ||
})); | ||
if ( response && response.output) | ||
response = {"url" : JSON.parse(response.output).url} | ||
return { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
const AWS = require('aws-sdk'); | ||
const s3 = new AWS.S3(); | ||
const polly = new AWS.Polly(); | ||
const uuidv1 = require('uuidv1'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Some error occurs.
|
||
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3'); | ||
const { PollyClient, SynthesizeSpeechCommand } = require('@aws-sdk/client-polly'); | ||
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner'); | ||
const { GetObjectCommand } = require('@aws-sdk/client-s3'); | ||
const { randomUUID } = require('crypto'); | ||
const s3 = new S3Client({}); | ||
const polly = new PollyClient({}); | ||
|
||
|
||
module.exports.handler = async (event, context) => { | ||
|
@@ -62,21 +65,28 @@ module.exports.handler = async (event, context) => { | |
|
||
console.log(speechParams) | ||
|
||
const response = await polly.synthesizeSpeech(speechParams).promise(); | ||
const response = await polly.send(new SynthesizeSpeechCommand(speechParams)); | ||
let audioStream = response.AudioStream; | ||
let key = uuidv1(); | ||
|
||
const chunks = []; | ||
for await (const chunk of audioStream) { | ||
chunks.push(chunk); | ||
} | ||
const audioBuffer = Buffer.concat(chunks); | ||
|
||
let key = randomUUID(); | ||
let params = { | ||
Bucket: outputBucket, | ||
Key: key + '.mp3', | ||
Body: audioStream | ||
Body: audioBuffer | ||
}; | ||
|
||
const s3Response = await s3.putObject(params).promise(); | ||
const s3Response = await s3.send(new PutObjectCommand(params)); | ||
let s3params = { | ||
Bucket: outputBucket, | ||
Key: key + '.mp3', | ||
}; | ||
let url = s3.getSignedUrl("getObject", s3params); | ||
let url = await getSignedUrl(s3, new GetObjectCommand(s3params)); | ||
console.log(url); | ||
return { url, outputBucket, key: key + '.mp3' }; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Some error occurs. Because we need use
connections
url with https.