Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Commit 7f84c71

Browse files
authored
Merge pull request #8 from localstack-samples/migrate-to-aws-endpoint-url
2 parents 98da89a + 7d51e9d commit 7f84c71

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/jobs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict';
22

33
const awsSdk = require('aws-sdk');
4-
const localstackHost = `http://${process.env.LOCALSTACK_HOSTNAME}:${process.env.EDGE_PORT}`
4+
5+
const endpoint = process.env.AWS_ENDPOINT_URL
6+
const s3 = new awsSdk.S3({endpoint: endpoint, s3ForcePathStyle: true});
57

68
// This function is triggered by an HTTP request using the GET method.
79
// The function returns a list of all the transcription jobs stored in the S3 bucket.
@@ -25,8 +27,6 @@ exports.list = async (event, context, callback) => {
2527
</ul>
2628
`
2729

28-
const s3 = new awsSdk.S3({endpoint:localstackHost, s3ForcePathStyle: true});
29-
3030
const bucketName = "aws-node-sample-transcribe-s3-local-transcriptions";
3131
const params = {
3232
Bucket: bucketName,

src/queue.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
const localstackHost = `http://${process.env.LOCALSTACK_HOSTNAME}:${process.env.EDGE_PORT}`;
21
const awsSdk = require('aws-sdk');
3-
const sqs = new awsSdk.SQS({endpoint:localstackHost});
4-
const ses = new awsSdk.SES({endpoint:localstackHost});
5-
const s3 = new awsSdk.S3({endpoint:localstackHost, s3ForcePathStyle: true});
2+
3+
const endpoint = process.env.AWS_ENDPOINT_URL;
4+
const sqs = new awsSdk.SQS({endpoint: endpoint});
5+
const ses = new awsSdk.SES({endpoint: endpoint});
6+
const s3 = new awsSdk.S3({endpoint: endpoint, s3ForcePathStyle: true});
7+
const queueUrl = `${endpoint}/000000000000/aws-node-sample-transcribe-s3-local-jobs`;
8+
const transcriptionBucket = process.env.S3_TRANSCRIPTION_BUCKET
69

710
// This function consumes the event from s3 PutObject and pushes a new message to SQS.
811
const producer = async (event, context, callback) => {
912
let statusCode = 200;
1013
let message;
1114

12-
const queueUrl = `http://${process.env.LOCALSTACK_HOSTNAME}:${process.env.EDGE_PORT}/000000000000/aws-node-sample-transcribe-s3-local-jobs`;
13-
1415
try {
1516
// Get the record from the s3 event
1617
const records = event.Records;
1718
const sqsSendMessagePromises = records.map((record) => {
1819
var jsonContent = "";
1920
const params = {
20-
Bucket: process.env.S3_TRANSCRIPTION_BUCKET,
21+
Bucket: transcriptionBucket,
2122
Key: record.s3.object.key
2223
};
2324
s3.getObject(params, (err, data) => {
2425
if (err) {
25-
console.error("Error getting object from S3 bucket: ", process.env.S3_TRANSCRIPTION_BUCKET)
26+
console.error("Error getting object from S3 bucket: ", transcriptionBucket)
2627
} else {
2728
jsonContent = JSON.parse(data.Body.toString());
2829

@@ -78,7 +79,7 @@ const consumer = async (event) => {
7879
},
7980
Subject: {
8081
Charset: "UTF-8",
81-
Data: "Test Email - JOB COMPLETED SUCESSFULLY"
82+
Data: "Test Email - JOB COMPLETED SUCCESSFULLY"
8283
}
8384
},
8485
Source: "sender@example.com" // Sender email address
@@ -97,4 +98,4 @@ const consumer = async (event) => {
9798
module.exports = {
9899
producer,
99100
consumer,
100-
};
101+
};

src/transcribe.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
const awsSdk = require('aws-sdk');
4-
const localstackHost = `http://${process.env.LOCALSTACK_HOSTNAME}:${process.env.EDGE_PORT}`
5-
const endpoint = new awsSdk.Endpoint(localstackHost);
4+
5+
const endpoint_url = process.env.AWS_ENDPOINT_URL
6+
const endpoint = new awsSdk.Endpoint(endpoint_url);
67
const endpointConfig = new awsSdk.Config({
78
endpoint: endpoint
89
});

0 commit comments

Comments
 (0)