Skip to main content

Posts

Showing posts from February, 2019

Saving data from S3 on RedShift with NodeJS

To save your data in RedShift you first need to download the pg module because in fact RedShift is a Postgres database. npm install pg If you have not already done so, install the amazon sdk with the following command: npm install aws-sdk We can now write our first lines of code to import these modules into our file: var AWS = require('aws-sdk'); const { Pool, Client } = require('pg'); Creating a connection pool with the database: let pool = new Pool({ user: user, host: 'your-endpoint.redshift.amazonaws.com', database: database-name, password: 'your-password', port: 5439, }); You need to create a table in the RedShift public schema with a column for each property in your json file. Your file must be in RJSON (relaxed json) format, that is, without commas between your objects. Let's create our table in RedShift with the following sql command : CREATE TABLE public.product ( title varchar(256) NOT NULL, brand var