Skip to content

Commit

Permalink
Siirron streamaus
Browse files Browse the repository at this point in the history
  • Loading branch information
augustk committed Dec 19, 2024
1 parent e4f2f4d commit 33ec369
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions lampi-siirtaja-container/lampi-siirtaja/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lampi-siirtaja-container/lampi-siirtaja/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"main": "dist/run.js",
"dependencies": {
"@aws-sdk/client-s3": "^3.715.0",
"@smithy/types": "^3.7.2",
"bindings": "^1.5.0",
"file-uri-to-path": "^1.0.0",
"libpq": "^1.8.13",
Expand Down
13 changes: 8 additions & 5 deletions lampi-siirtaja-container/lampi-siirtaja/src/run.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import PgClient from 'pg-native';

import { NodeJsClient } from "@smithy/types";
import {
S3Client,
CopyObjectCommand,
ObjectNotInActiveTierError,
waitUntilObjectExists, GetObjectCommand, GetObjectCommandOutput, PutObjectCommand, PutObjectCommandOutput,
} from '@aws-sdk/client-s3';
import { Readable } from 'node:stream';

const dbHost = process.env.POSTGRES_HOST;
const dbUsername = process.env.DB_USERNAME;
Expand Down Expand Up @@ -62,8 +63,8 @@ const copyTableToS3 = (schemaName: string, tableName: string) => {
}

const copyFileToLampi = async (sourceKey: string): Promise<ManifestItem> => {
const ovaraS3Client: S3Client = new S3Client({});
const lampiS3Client: S3Client = new S3Client({});
const ovaraS3Client: S3Client = new S3Client({}) as NodeJsClient<S3Client>;
const lampiS3Client: S3Client = new S3Client({}) as NodeJsClient<S3Client>;
const destinationKey = sourceKey;

const getObjectCommandOutput: GetObjectCommandOutput = await ovaraS3Client.send(
Expand All @@ -73,13 +74,15 @@ const copyFileToLampi = async (sourceKey: string): Promise<ManifestItem> => {
}),
);

const bodyString: string = await getObjectCommandOutput.Body.transformToString();
//const bodyString: string = await getObjectCommandOutput.Body.transformToString();

const putObjectCommandOutput: PutObjectCommandOutput = await lampiS3Client.send(
new PutObjectCommand({
Bucket: lampiS3Bucket,
Key: destinationKey,
Body: bodyString
Body: getObjectCommandOutput.Body,
ContentLength: getObjectCommandOutput.ContentLength
//Body: bodyString
})
);

Expand Down

0 comments on commit 33ec369

Please sign in to comment.