Skip to content

Instantly share code, notes, and snippets.

View mobilequickie's full-sized avatar

Mobile Quickie mobilequickie

View GitHub Profile
@mobilequickie
mobilequickie / CreateAuthChallenge.js
Last active August 4, 2023 03:45
Amazon Cognito CUSTOM_CHALLENGE Lambda trigger - Create Auth Challenge function
// ### About this Flow ###
// Using Custom Auth Flow through Amazon Cognito User Pools with Lambda Triggers to complete a 'CUSTOM_CHALLENGE'.
//
// ### About this function ###
// This CreateAuthChallengeSMS function (2nd of 4 triggers) creates the type of 'CUSTOM_CHALLENGE' as a one-time pass code sent via SMS. A one-time randomly generated 6-digit code (passCode)
// is sent via SMS (through Amazon SNS) to the user's mobile phone number during authentication. The generated passCode is stored in privateChallengeParameters.passCode and passed to the VerifyAuthChallenge function
// that will verify the user's entered passCode (received via SMS) into the mobile/web app matches the passCode passed privately through privateChallengeParameters.passCode.
// ### Next steps ###
// Instead of using the "crypto-secure-random-digit" library to generate random 6-digit codes, create a base32 secret for the user (if not exist) and
@mobilequickie
mobilequickie / DefineAuthChallenge.js
Last active August 4, 2023 03:46
Amazon Cognito CUSTOM_CHALLENGE Lambda trigger - Define Auth Challenge function
// ### About this Flow ###
// Using Custom Auth Flow through Amazon Cognito User Pools with Lambda Triggers to complete a 'CUSTOM_CHALLENGE'. This is the same flow as one-time passcode generated and sent via SMS or Email.
// Instead, the service and user share a secret that was created during registration and both generate a 6-digit code based on the shared secret.
// If the two codes (typically only good for 30 seconds) match, the user is authenticated.
//
// ### About this function ###
// This DefineAuthChallengeCustom function (1st and 4th of 4 triggers) defines the type of challenge-response required for authentication.
// For HOTP, TOTP, U2F, or WebAuthn flows, we'll always use 'CUSTOM_CHALLENGE' and this function code won't change between the various auth methods.
// ### Next steps ###
@mobilequickie
mobilequickie / RDSDemo-AppSync-Query.swift
Created May 24, 2019 20:00
RDSDemo - GraphQL Query
// GraphQL Query - List all AWS Services from MyAWSServices Table
// Returned cached list and then fetch
func getServicesQuery(){
appSyncClient?.fetch(query: ListAwsServicesQuery(), cachePolicy: .returnCacheDataAndFetch) { (result, error) in
if error != nil {
print(error?.localizedDescription ?? "")
return
}
guard let services = result?.data?.listAwsServices else { return }
@mobilequickie
mobilequickie / RDSDemo-Mutation.swift
Last active May 24, 2019 19:41
RDSDemo for GraphQL mutation for iOS
// GraphQL Mutation - Add a new AWS Service to the MyAWSService database table
func createServiceMutation(){
// A quick sample insert
let createServiceInput = CreateAWSServiceInput(id: 6, shortName: "Device Farm", longName: "AWS Device Farm", serviceRegionName: "aws-device-farm-us-west-2", imageUrl: "device-farm")
appSyncClient?.perform(mutation: CreateAwsServiceMutation(createAWSServiceInput: createServiceInput)) {
(result, error) in
if let error = error as? AWSAppSyncClientError {
print("Error occurred: \(error.localizedDescription )")
}
import UIKit
import AWSAppSync // #1
class AWSServicesTableViewController: UITableViewController {
// Reference AppSync client
var appSyncClient: AWSAppSyncClient? // #2
// Sample data
@mobilequickie
mobilequickie / lambda-rdsdataservice-dataapi-function.js
Last active August 24, 2022 17:51
AWS Lambda function (Node 8) using the RDSDataService API to connect to an Aurora Serverless Data API enabled MySQL database
// As of April 25, 2019 --> Make sure to call $ 'npm install aws-sdk' to package this function before deploying to Lambda as the RDSDataService API is currently in BETA and
// therefore not available in the default aws-sdk included in the Node 8 engine built into Lambda.
// This code uses RDSDataService API for connecting to a Data API enabled Aurora Serverless database: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/RDSDataService.html
// Call this function with: { "sqlStatement": "SELECT * FROM <YOUR-TABLE-NAME"}
// Deploy this Lambda function via CloudFormation here: https://github.com/mobilequickie/rds-aurora-mysql-serverless
const AWS = require('aws-sdk')
const RDS = new AWS.RDSDataService()
exports.handler = async (event, context) => {
@mobilequickie
mobilequickie / create-customer-serverless-db-graphql-mutation
Created April 23, 2019 23:41
A sample mutation for creating a new customer in the Customers table of an Aurora Serverless Data API enabled database as a datastore for AWS AppSync
mutation CreateCustomer {
createCustomers(createCustomersInput: {
id: 2,
name: "Customer Two",
phone: "206-555-xxxx",
email: "cust@customertwo.com"
}) {
id
name
phone
@mobilequickie
mobilequickie / sqlStatement-aurora-db-serverless-dataAPI.awscli
Created April 23, 2019 21:47
Executing a select * statement against an Aurora Serverless Data API enabled database using the "rds-data" API from the AWS CLI
//Select * query from Aurora Serverless (w/ Data API enabled) using the "execute-sql" API
aws rds-data execute-sql --db-cluster-or-instance-arn "arn:aws:rds:us-east-1:xxxxxxxxxxxx:cluster:my-serverless-cluster" --schema "" \
--database "MarketPlace" --aws-secret-store-arn "arn:aws:secretsmanager:us-east-1:xxxxxxxxxxxx:secret:RDSAuroraServerlessMasterSecret-3haLhV" \
--sql-statements "select * from Customers" --region us-east-1 \
--endpoint-url https://rds-data.us-east-1.amazonaws.com
@mobilequickie
mobilequickie / create-aurora-db-serverless.awscli
Last active May 4, 2020 00:46
Create an Aurora Serverless Cluster via AWS CLI
aws rds create-db-cluster --db-cluster-identifier my-serverless-cluster --master-username mymasteruser \
--master-user-password mymasterpassword --engine aurora --engine-mode serverless \
--region us-east-1
@mobilequickie
mobilequickie / LWAViewController.swift
Last active April 26, 2019 03:36
Login with Amazon using AWSMobileClient integration sample main ViewController
//
// ViewController.swift
// AuthLWA
//
// Created by Hills, Dennis on 4/26/19.
// Copyright © 2018 Hills, Dennis. All rights reserved.
//
// Gist: https://gist.github.com/mobilequickie/77c60e2204e759ed0a72bde0478c0885
//
import UIKit