Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Yossale yossale

💭
I may be slow to respond.
View GitHub Profile
@yossale
yossale / AppSync-Example.yaml
Created Apr 10, 2022 — forked from adrianhall/AppSync-Example.yaml
An example CloudFormation template for AWS AppSync
View AppSync-Example.yaml
---
Description: AWSAppSync DynamoDB Example
Resources:
GraphQLApi:
Type: "AWS::AppSync::GraphQLApi"
Properties:
Name: AWSAppSync DynamoDB Example
AuthenticationType: AWS_IAM
PostDynamoDBTableDataSource:
@yossale
yossale / verify.js
Last active Oct 13, 2020
JWT Verificaiton
View verify.js
const jwt = require('jsonwebtoken');
const fs = require('fs')
function decode(token, pemFile) {
let cert = fs.readFileSync(pemFile); // get public key
jwt.verify(token, cert, function (err, decoded) {
if (err) {
console.error("Error", err)
}
console.log(`${JSON.stringify(decoded)}`)
@yossale
yossale / sign.js
Last active Oct 13, 2020
JWT Signing Lambda
View sign.js
const AWS = require("aws-sdk");
const kms = new AWS.KMS();
const util = require('util')
const base64url = require("base64url");
const keyId = '<YOUR_KEY_ID>'
async function sign(headers, payload, key_arn) {
payload.iat = Math.floor(Date.now() / 1000);
@yossale
yossale / ScalableWebhook-processing.js
Created Jul 28, 2020
Scalable Webhook - Sample code for the Processing function
View ScalableWebhook-processing.js
const util = require('util')
const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient();
const REQ_TABLE = process.env.TABLE_REQUESTSTABLE01
async function updateUserProductsByEmailId(emailId) {
console.info(`Updating user products for email: ${emailId}`)
//Update all the user-specific products as seen
@yossale
yossale / ScalableWebhook-enqueue.js
Created Jul 28, 2020
Scalable Webhook - Sample code for the Enqueue function
View ScalableWebhook-enqueue.js
const AWS = require('aws-sdk')
const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
const queueUrl = process.env.QUEUE_REQUESTSQUEUE01
function isValidMessage(msg) {
console.info(`Verifying message [${msg}]`)
//Do some verification logic here
return true
@yossale
yossale / ScalableWebhook-CF_template_1.json
Created Jul 28, 2020
Scalable Webhook - Basic CloudFormation Template (Before limiting concurrency and adding DLQ)
View ScalableWebhook-CF_template_1.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"ApiGateway01": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "Prod"
}
},
@yossale
yossale / additionalFuncResources.json
Created Jun 22, 2020
Log Group creation and subscription
View additionalFuncResources.json
"Func01LogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": {
"Fn::Sub": [
"/aws/Lambda/${LambdaName}",
{
"LambdaName": {
"Ref": "Func01Name"
}
@yossale
yossale / logGroupListener-permission.json
Created Jun 22, 2020
logGroupListener-permission.json
View logGroupListener-permission.json
{
"Version": "2012–10–17",
"Statement": [
{
"Sid": "Manual",
"Effect": "Allow",
"Action": "logs:PutSubscriptionFilter",
"Resource": "arn:aws:logs:us-east-1:{YOUR_ACCOUNT_ID}:log-group:/aws/Lambda/*"
}
]
@yossale
yossale / logGroupEvent.json
Created Jun 22, 2020
LogGroupCreate CloudWatch Event
View logGroupEvent.json
{
"source": [
"aws.logs"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"logs.amazonaws.com"
View LogGroupListenerTemplate.json
{
"AWSTemplateFormatVersion":"2010-09-09",
"Transform":"AWS::Serverless-2016-10-31",
"Resources":{
"StackUpdatesListener01":{
"Type":"AWS::Serverless::Function",
"Properties":{
"InlineCode": "module.exports.handler = async (event, context) => { console.log('LOGGING', context); return { statusCode: 200 } }",
"Handler": "index.handler",
"Runtime":"nodejs12.x",