Skip to content

Instantly share code, notes, and snippets.

View pandeysoni's full-sized avatar
🎯
Focusing

Soni Pandey pandeysoni

🎯
Focusing
  • India
View GitHub Profile
import React, { useState } from "react";
import {Auth} from 'aws-amplify';
const CustomSignIn = (props) => {
const {authState, onStateChange} = props;
const [formData, setFormData] = useState({
username: '',
password: '',
code: ''
});
service: user-service
provider:
name: aws
profile: ${self:custom.config.profile}
runtime: nodejs12.x
region: ${self:custom.config.region}
stage: ${self:custom.config.stage}
memorySize: 128
timeout: 30
const GoogleAuth = require('google-auth-library');
const auth = new GoogleAuth;
const clientId = 'clientid';
const clientSecret = 'clientSecret';
const client = new auth.OAuth2(clientId, clientSecret, '');
const Oauth = require('../businesslogic/oauth');
const async = require('async');
exports.oauth = (event, context, callback) => {
async.waterfall([
const AWS = require('aws-sdk');
const athena = new AWS.Athena({
region: 'us-west-2'
})
function createQueryExecutionId(){
/**doing resultConfiguration, but we will not save query result there. */
const params = {
QueryString: queryParams, /* required */
ResultConfiguration: { /* required */

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
const AWS = require('aws-sdk')
const async = require('async')
const bucketName = "pandeysoni"
const path = require('path')
const fs = require('fs')
let pathParams, image, imageName;
/** Load Config File */
AWS.config.loadFromPath('config.json')
Download- [Dynamodb_local](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html#DynamoDBLocal.DownloadingAndRunning) - extract Dyanodb_local and run jar file with these command
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedD b -inMemory
Set - Config and credentials
in Windows -
C:\Users\<User>\.aws\config
C:\Users\<User>\.aws\credentials
Install aws-sdk locally
and then follow http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.03.html
const randomstring = require("randomstring")
exports.forgotPassword = function (req, res){
var random = Common.encrypt(randomstring.generate({length: 5, charset: 'alphabetic'}));
User.findUserUpdate({username: req.body.username}, {password: random}, function(err, user) {
if (!err) {
if (user === null){
return res.send(Boom.forbidden("invalid username"));
}
else{
Common.sentMailForgotPassword(user);
const express = require('express')
const Routes = require('./server/routes')
const config = require('./server/config/config')
const bodyParser = require('body-parser')
const app = express()
const db = require('./server/config/db')
const path = require('path')
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
/**Add all configuration settings here*/
module.exports = {
mailUser: senderEmail,
mailPass: senderPass
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken
}