Skip to content

Instantly share code, notes, and snippets.

View apal21's full-sized avatar
:octocat:
Web development | DevOps

Apal Shah apal21

:octocat:
Web development | DevOps
View GitHub Profile
@apal21
apal21 / Nextjs Progressbar.js
Last active January 25, 2019 09:11
This code is used to make custom Next.js progressbar using NProgress module. If you directly want to use this module as an NPM package, here is the link: https://www.npmjs.com/package/nextjs-progressbar
import React from 'react';
import NProgress from 'nprogress';
import Router from "next/router";
import PropTypes from 'prop-types';
/* eslint-disable react/prefer-stateless-function */
class NextNProgress extends React.Component {
static defaultProps = {
color: '#29D',
startPosition: 0.3,
@apal21
apal21 / AWS STS generate credentials using callback.js
Last active January 25, 2019 18:58
Sample code to assume role and generate temporary credentials using a callback
const AWS = require('aws-sdk');
const sts = new AWS.STS();
sts.assumeRole({
DurationSeconds: 3600,
ExternalId: '1234-1234-1234-1234-1234',
RoleArn: "Your Role ARN",
RoleSessionName: 'abc'
}, (err, data) => {
if (err) throw err;
@apal21
apal21 / AWS STS generate credentials using async-await.js
Created January 25, 2019 09:27
Sample code to assume role and generate temporary credentials using async/await
const AWS = require('aws-sdk');
const sts = new AWS.STS();
(async () => {
try {
const data = await sts.assumeRole({
DurationSeconds: 3600,
ExternalId: '1234-1234-1234-1234-1234',
RoleArn: "Your Role ARN",
@apal21
apal21 / AWS STS generate credentials using then().js
Created January 25, 2019 09:50
Sample code to assume role and generate temporary credentials using .then()
const AWS = require('aws-sdk');
const sts = new AWS.STS();
sts
.assumeRole({
DurationSeconds: 3600,
ExternalId: '1234-1234-1234-1234-1234',
RoleArn: 'Your Role ARN',
RoleSessionName: 'abc',
})
@apal21
apal21 / getSignedUrl synchronous.js
Created January 25, 2019 19:10
AWS S3 getSignedUrl synchronously
const s3 = new AWS.S3(accessparams);
const url = s3.getSignedUrl('getObject', {
Bucket: 'BUCKET-NAME',
Key: 'path/to/your/file',
Expires: 60 * 5 // time in seconds: e.g. 60 * 5 = 5 mins
})
console.log(url);
@apal21
apal21 / getSignedUrl callback.js
Created January 25, 2019 19:14
AWS S3 getSignedUrl using a callback
const s3 = new AWS.S3(accessparams);
s3.getSignedUrl('getObject', {
Bucket: 'BUCKET-NAME',
Key: 'path/to/your/file',
Expires: 60 * 5, // time in seconds: e.g. 60 * 5 = 5 mins
}, (err, url) => {
if (err) throw err;
console.log(url);
});
@apal21
apal21 / getObject callback.js
Created January 25, 2019 19:24
AWS S3 getObject using a callback
const s3 = new AWS.S3(accessparams);
s3.getObject(
{ Bucket: 'BUCKET-NAME', Key: 'path/to/your/file' },
(err, file) => {
if (err) throw err;
console.log(file.Body);
}
);
@apal21
apal21 / getObject .then().js
Created January 25, 2019 19:33
AWS S3 getObject using .then()
const s3 = new AWS.S3(accessparams);
s3.getObject({ Bucket: 'BUCKET-NAME', Key: 'path/to/your/file' })
.promise()
.then(file => {
console.log(file.Body);
})
.catch(err => {
console.log(err);
});
@apal21
apal21 / S3 getObject async-await.js
Last active March 20, 2024 19:47
AWS S3 getObject using async/await
const s3 = new AWS.S3(accessparams);
(async () => {
try {
const file = await s3
.getObject({ Bucket: 'BUCKET-NAME', Key: 'path/to/your/file' })
.promise();
console.log(file.Body);
} catch (err) {
console.log(err);
@apal21
apal21 / CloudFront Signed URL Canned Policy.js
Last active February 5, 2019 09:09
Example to generate Signed URLs in CloudFront using Canned Policy.
const AWS = require('aws-sdk');
// Try to use process.env.PRIVATE_KEY instead of exposing your key
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
-----END RSA PRIVATE KEY-----`