Skip to content

Instantly share code, notes, and snippets.

View erankitcs's full-sized avatar
🏏

Ankit K Singh erankitcs

🏏
View GitHub Profile
@erankitcs
erankitcs / image_controller.js
Created March 14, 2021 12:59
Java script code which receives real-time events from Firestore.
var imageController = {
data: {
config: null
},
uiElements: {
imageCardTemplate: null,
imageList: null,
loadingIndicator: null
},
init: function (config,firebaseConfig) {
@erankitcs
erankitcs / firestore_insert_lambda.js
Created March 14, 2021 12:53
AWS Lambda function to push data into GCP Firestore.
'use strict';
const admin = require('firebase-admin');
const serviceAccount = require('serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
@erankitcs
erankitcs / firestore.tf
Last active March 14, 2021 12:39
Terraform code to create GCP project along with Firestore.
provider "google" {
user_project_override = true
}
resource "google_firebase_project" "firebase" {
provider = google-beta
project = var.gcp_project_name
}
resource "google_app_engine_application" "imagelense" {
@erankitcs
erankitcs / analyse_image.js
Created March 14, 2021 12:06
Lambda function to call Azure Cognitive Computer Vision API.
'use strict'
const request = require('request');
const AWS = require('aws-sdk');
const s3 = new AWS.S3({signatureVersion: 'v4'});
const ssm = new AWS.SSM();
let subscriptionKeyPS = process.env['COMPUTER_VISION_SUBSCRIPTION_KEY_PS']
let endpoint = process.env['COMPUTER_VISION_ENDPOINT'] + '/vision/v2.1/analyze'
let topic = process.env['TOPIC_ARN']
@erankitcs
erankitcs / azure_congnitive_with_aws_parameterstore.tf
Created March 14, 2021 11:55
Azure Service Account for Cognitive Services in Terraform and store secrets into AWS Parameter Store.
provider "azurerm" {
version = "=2.0.0"
### Fix for Error: "features": required field is not set
features {}
skip_provider_registration = true
}
provider "aws" {
region = "us-east-1"
}
@erankitcs
erankitcs / uplaod_controller.js
Created March 14, 2021 11:47
Java script function to call API gateway and upload image into S3 bucket.
var uploadController = {
data: {
config: null
},
uiElements: {
uploadButton: null
},
init: function (configConstants) {
console.log('Init function.')
this.data.config = configConstants;
@erankitcs
erankitcs / presinged_s3_write_lambda.js
Created March 14, 2021 11:41
Lambda function to generate pre signed s3 write URL
'use strict';
const AWS = require('aws-sdk');
const crypto = require('crypto');
const s3 = new AWS.S3({signatureVersion: 'v4'});
const generateResponse = (status, message) => {
return {
statusCode: status,
headers: { 'Access-Control-Allow-Origin': '*' },
body : JSON.stringify(message)
@erankitcs
erankitcs / api-gateway.tf
Created March 14, 2021 11:12
API Gateway setup for Lambda function.
resource "aws_api_gateway_rest_api" "imagelenseapi" {
name = "imagelenseApi"
description = "Image Analyser API for web application."
}
resource "aws_api_gateway_resource" "imagelenseapi_res" {
rest_api_id = aws_api_gateway_rest_api.imagelenseapi.id
parent_id = aws_api_gateway_rest_api.imagelenseapi.root_resource_id
path_part = "presigneds3url"
}
@erankitcs
erankitcs / ASGInstanceRefeshLambdaFunction.py
Last active November 7, 2022 12:28
AWS Autoscaling Group Instance Refresh Lambda Function
import json
import boto3
from botocore.exceptions import ClientError
import logging
import os
logger = logging.getLogger()
logger.setLevel(logging.INFO)
#ec2_client = boto3.client('ec2')
asg_client = boto3.client('autoscaling')
@erankitcs
erankitcs / 1.web_ami_image.json
Last active April 5, 2022 14:53
Packer Image builder and CI/CD Pipeline
{
"variables": {
"aws_region": "us-east-1",
"base_ami": ""
},
"builders": [
{
"type": "amazon-ebs",
"region": "{{user `aws_region`}}",
"source_ami": "{{user `base_ami`}}",