Skip to content

Instantly share code, notes, and snippets.

View yossale's full-sized avatar
💭
I may be slow to respond.

Yossale yossale

💭
I may be slow to respond.
View GitHub Profile
@yossale
yossale / AppSync-Example.yaml
Created April 10, 2022 13:27 — forked from adrianhall/AppSync-Example.yaml
An example CloudFormation template for AWS AppSync
---
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 October 13, 2020 15:42
JWT Verificaiton
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 October 13, 2020 15:42
JWT Signing Lambda
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 July 28, 2020 09:27
Scalable Webhook - Sample code for the Processing function
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 July 28, 2020 09:26
Scalable Webhook - Sample code for the Enqueue function
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 July 28, 2020 09:06
Scalable Webhook - Basic CloudFormation Template (Before limiting concurrency and adding DLQ)
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"ApiGateway01": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "Prod"
}
},
@yossale
yossale / additionalFuncResources.json
Created June 22, 2020 08:18
Log Group creation and subscription
"Func01LogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": {
"Fn::Sub": [
"/aws/Lambda/${LambdaName}",
{
"LambdaName": {
"Ref": "Func01Name"
}
@yossale
yossale / logGroupListener-permission.json
Created June 22, 2020 07:56
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 June 22, 2020 07:53
LogGroupCreate CloudWatch Event
{
"source": [
"aws.logs"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"logs.amazonaws.com"
{
"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",