Skip to content

Instantly share code, notes, and snippets.

View mobilequickie's full-sized avatar

Mobile Quickie mobilequickie

View GitHub Profile
platform :ios, '11.0'
target 'AuthLWA' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Auth
pod 'AWSMobileClient', '~> 2.9.0'
end
@mobilequickie
mobilequickie / LWAViewController-Federated.swift
Last active August 6, 2020 07:44
This is working ViewController that authenticates with Login with Amazon and uses the LoginWithAmazonProxy gist code.
//
// ViewController.swift
// AuthLWA with AWSMobileClient using Federated Identities
//
// Created by Hills, Dennis on 4/26/19.
// Copyright © 2019 Hills, Dennis. All rights reserved.
//
// Requires LoginWithAmazonProxy via Gist here: https://gist.github.com/mobilequickie/56916503a41ebb2374fea241ede26eab
// This gist: https://gist.github.com/mobilequickie/47a238e073043a271425f7ffe9d56d5e
//
@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
@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 / 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-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: "[email protected]"
}) {
id
name
phone
@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) => {
import UIKit
import AWSAppSync // #1
class AWSServicesTableViewController: UITableViewController {
// Reference AppSync client
var appSyncClient: AWSAppSyncClient? // #2
// Sample data
@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 )")
}
@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 }