├── test3 ├── .gitignore ├── gitignore.backup ├── awsLambdaTest ├── event.json ├── index.js └── readme.md ├── awsCloudformationRunLambda ├── .DS_Store ├── runOnce.zip ├── index.js ├── customResourceRunLambda.yaml ├── deploy.sh ├── readme.md └── cfn-response.js ├── oktaMultipleLoginPage ├── images │ └── pony.png ├── index.html └── readme.md ├── gitignore └── readme.md ├── amazonDeleteS3Buckets └── readme.md ├── awsLambdaStock └── readme.md ├── amazonDeleteCloudLogs └── readme.md ├── amazonLambdaMisc └── readme.md ├── awsSam2 ├── src │ └── index.js ├── deploy.sh ├── template.yaml ├── readme.md └── output.yaml ├── awsS3DeleteBucketsWithVersioning └── readme.md ├── awsSam ├── HelloWorld │ └── lambda_function.py ├── 01-basic-sam-template.yaml ├── TestAuthorizerFunc │ └── lambda_function.py ├── deploy.sh ├── 02-sam-swagger-tamplate.yaml ├── 03-sam-swagger-auth-template.yaml └── readme.md ├── oktaKeystore └── readme.md ├── awsSamOktaRental ├── bookings │ └── index.js ├── deploy.sh ├── readme.md ├── template.yaml └── vehicles │ └── index.js ├── awsOktaRentalWithAuthorizer ├── bookings │ └── index.js ├── authorizer │ └── authorizer.js ├── deploy.sh ├── readme.md ├── template.yaml └── vehicles │ └── index.js ├── awsCloudformationMakeBucket ├── readme.md ├── template.yml ├── deploy.sh └── setups3bucket │ ├── cfn-response.js │ ├── index.js │ └── oktaLoginPage.html ├── starterHTML └── readme.md ├── amazonS3CommonCommands └── readme.md ├── securityCertificatesCreate └── readme.md ├── dockerNginxHacking └── readme.md ├── amazonLambdaUpload └── readme.md ├── dockerSnapshot └── readme.md ├── awsAnythingGoesAuthorizer ├── denyAnything.js ├── allowAnything.js └── readme.md ├── angularNotes └── readme.md ├── awsLaunchStack ├── launchstack.yaml └── readme.md ├── awsCustomResourceOutput └── readme.md ├── awsSamOktaGuest ├── deploy.sh ├── output.yaml ├── template.yaml ├── src │ └── index.js └── readme.md ├── lambdaEdgeStaticWebpage └── readme.md ├── phpDecodeJwt └── readme.md ├── awsCloudformationInlineLambdaWithRole └── readme.md ├── loginWidgetCorsOnPhp └── readme.md ├── oktaServer ├── Dockerfile └── readme.md ├── nodeRandomSnippets └── readme.md ├── javascriptPromises └── readme.md ├── awsCloudformationCustomResourceOrchestration └── readme.md ├── lambdaEdgeSetCookie └── readme.md ├── loginWidgetJsfiddle └── readme.md ├── readme.md └── loginWidgetBootstrap ├── index.html └── readme.md /test3: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | node_modules/* 3 | bin/* 4 | pkg/* 5 | src/github.com/* 6 | 7 | -------------------------------------------------------------------------------- /gitignore.backup: -------------------------------------------------------------------------------- 1 | .idea/* 2 | node_modules/* 3 | bin/* 4 | pkg/* 5 | src/github.com/* 6 | 7 | -------------------------------------------------------------------------------- /awsLambdaTest/event.json: -------------------------------------------------------------------------------- 1 | { 2 | "key3": "value3", 3 | "key2": "value2", 4 | "key1": "value1" 5 | } 6 | 7 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmcdowell-okta/my-notes/HEAD/awsCloudformationRunLambda/.DS_Store -------------------------------------------------------------------------------- /oktaMultipleLoginPage/images/pony.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmcdowell-okta/my-notes/HEAD/oktaMultipleLoginPage/images/pony.png -------------------------------------------------------------------------------- /awsCloudformationRunLambda/runOnce.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmcdowell-okta/my-notes/HEAD/awsCloudformationRunLambda/runOnce.zip -------------------------------------------------------------------------------- /awsLambdaTest/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | // TODO implement 3 | callback(null, 'Hello from Lambda'); 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /gitignore/readme.md: -------------------------------------------------------------------------------- 1 | ### Git Ignore 2 | 3 | This is the code I use to prevent get from fetching my .idea and other files. 4 | 5 | ``` 6 | .idea/* 7 | node_modules/* 8 | bin/* 9 | pkg/* 10 | src/github.com/* 11 | ``` 12 | 13 | 14 | -------------------------------------------------------------------------------- /amazonDeleteS3Buckets/readme.md: -------------------------------------------------------------------------------- 1 | ### Delete all S3 Buckets 2 | 3 | *Use at your own Risk*, this has saved me a lot of time during testing. Clear out your S3 Buckets. 4 | 5 | ``` 6 | aws s3 ls | cut -d" " -f 3 | xargs -I{} aws s3 rb s3://{} --force 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /awsLambdaStock/readme.md: -------------------------------------------------------------------------------- 1 | ### Stock Lambda Function in AWS 2 | 3 | nothing special here, this is the beginning of a Lambda Function in AWS 4 | 5 | ``` 6 | exports.handler = (event, context, callback) => { 7 | // TODO implement 8 | callback(null, 'Hello from Lambda'); 9 | }; 10 | ``` 11 | 12 | -------------------------------------------------------------------------------- /amazonDeleteCloudLogs/readme.md: -------------------------------------------------------------------------------- 1 | ## Delete all Cloud Logs 2 | 3 | This is super helpful when you are debugging. 4 | 5 | ``` 6 | aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | awk '{print $2}' | grep -v ^$ | while read x; do aws logs delete-log-group --log-group-name $x; done 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /amazonLambdaMisc/readme.md: -------------------------------------------------------------------------------- 1 | ### Misc other commands I use when working with Lambdas 2 | 3 | list functions: 4 | `aws lambda list-functions` 5 | 6 | list functions, just names: 7 | `aws lambda list-functions | grep -i functionName` 8 | 9 | delete functions: 10 | `aws lambda delete-function --function-name TryCallBack` 11 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/index.js: -------------------------------------------------------------------------------- 1 | var response = require('cfn-response'); 2 | 3 | exports.handler = (event, context, callback) => { 4 | // TODO implement 5 | 6 | console.log("runOnceRan!"); 7 | 8 | //callback(null, 'Hello from Lambda'); 9 | 10 | response.send(event, context, response.SUCCESS, {"1":"2"}); 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /awsSam2/src/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | // TODO implement 3 | 4 | var response = { 5 | statusCode: 200, 6 | body: JSON.stringify("Cool you got response"), 7 | "isBase64Encoded": false 8 | }; 9 | console.log("response: " + JSON.stringify(response)) 10 | callback(null, response); 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /awsS3DeleteBucketsWithVersioning/readme.md: -------------------------------------------------------------------------------- 1 | ### Deleting buckets with Versioning is a HASTLE.. 2 | 3 | This script worked for me.. Thx who ever posted in 4 | 5 | ``` 6 | import boto3 7 | 8 | BUCKET = 'elasticbeanstalk-us-west-2-761861444952' 9 | 10 | s3 = boto3.resource('s3') 11 | bucket = s3.Bucket(BUCKET) 12 | bucket.object_versions.delete() 13 | ``` 14 | 15 | 16 | -------------------------------------------------------------------------------- /awsSam/HelloWorld/lambda_function.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | 4 | def lambda_handler(event, context): 5 | return response('Hello World!', 200) 6 | 7 | 8 | def response(message, status_code): 9 | return { 10 | 'isBase64Encoded': False, 11 | 'statusCode': status_code, 12 | 'body': json.dumps(message), 13 | 'headers': {'Content-Type': 'application/json'} 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /awsCloudformationRunLambda/customResourceRunLambda.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: Can you make a Lambda Function run 4 | 5 | 6 | Resources: 7 | test: 8 | Type: Custom::test 9 | Properties: 10 | ServiceToken: arn:aws:lambda:us-east-1:761861444952:function:runOnce 11 | # Input: some input 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /oktaKeystore/readme.md: -------------------------------------------------------------------------------- 1 | ### Okta Keystore for On Premise Agents. 2 | 3 | If you are working with Okta On Premise Agent, and using HTTPS, you need to add the Okta Key to the JRE's keystore (or vice a versa), but this is the command you will need to do that. 4 | 5 | Only took 3 hours for me to figure that out. 6 | 7 | `keytool -keystore cacerts -import -alias localhost -file /okta/server.crt` 8 | 9 | Add key to On Prem provisioning JRE 10 | 11 | -------------------------------------------------------------------------------- /awsSamOktaRental/bookings/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var bookings= { 4 | "vehicle_id":"733-23-13", 5 | "estimated_cost":"$ 120.00 USD", 6 | "confirmation_code":"HEUWIDWHDJIWY" 7 | } 8 | 9 | var response = { 10 | statusCode: 200, 11 | body: JSON.stringify(bookings), 12 | "isBase64Encoded": false 13 | }; 14 | console.log("response: " + JSON.stringify(response)) 15 | callback(null, response); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/bookings/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var bookings= { 4 | "vehicle_id":"733-23-13", 5 | "estimated_cost":"$ 120.00 USD", 6 | "confirmation_code":"HEUWIDWHDJIWY" 7 | } 8 | 9 | var response = { 10 | statusCode: 200, 11 | body: JSON.stringify(bookings), 12 | "isBase64Encoded": false 13 | }; 14 | console.log("response: " + JSON.stringify(response)) 15 | callback(null, response); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/readme.md: -------------------------------------------------------------------------------- 1 | ### Cloudformation template that creates S3 Bucket with login widget 2 | 3 | This project creates an S3 Bucket, then puts the HTML for an 4 | Okta Login widget on it. And when deleted, removes everything. 5 | 6 | #### To run it from the command line 7 | 8 | `./deploy.sh oktacoder77 makebucket24 template.yml --parameter-overrides oktaOrg=companyx.okta.com bucketname=saturday8834` 9 | 10 | #### To Delete the Stack 11 | `aws cloudformation delete-stack --stack-name makebucket23` -------------------------------------------------------------------------------- /awsSam/01-basic-sam-template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: An example serverless "Hello World" application. 4 | 5 | Resources: 6 | HelloWorld: 7 | Type: AWS::Serverless::Function 8 | Properties: 9 | Handler: lambda_function.lambda_handler 10 | Runtime: python3.6 11 | CodeUri: ./HelloWorld 12 | Events: 13 | GetApi: 14 | Type: Api 15 | Properties: 16 | Path: / 17 | Method: get 18 | -------------------------------------------------------------------------------- /starterHTML/readme.md: -------------------------------------------------------------------------------- 1 | #### Convenient to have some simple HTML with javascript ready to run, this is what I often start with. Similar to what you get with JSFiddle. 2 | 3 | 4 | 5 | ``` 6 | 7 | 8 | 9 | 10 | 15 |
16 | 17 |hi
19 | 20 | 21 | 22 | 23 | ``` 24 | -------------------------------------------------------------------------------- /amazonS3CommonCommands/readme.md: -------------------------------------------------------------------------------- 1 | ### Common Commands you should know when working with S3 2 | 3 | #### Make bucket 4 | `aws s3 mb s3://123demo123` 5 | 6 | #### List buckets 7 | `aws s3 ls` 8 | 9 | #### Copy files 10 | `aws s3 cp . s3://bucketname` 11 | 12 | #### Delete S3 Bucket 13 | `aws s3 rb "s3://authorizer8-dev-serverlessdeploymentbucket-16pc0b9h3515g" --force` 14 | 15 | #### S3 Sync 16 | `aws s3 sync . s3://my-bucket/path` 17 | 18 | #### Delete multiple buckets 19 | `for kk in $(aws s3 ls | grep -i golang | cut -f3 -d ' '); do $(aws s3 rb s3://$kk --force) ;done` 20 | -------------------------------------------------------------------------------- /securityCertificatesCreate/readme.md: -------------------------------------------------------------------------------- 1 | #### Make Certificates super fast 2 | 3 | ``` 4 | #!/usr/bin/env bash 5 | case `uname -s` in 6 | Linux*) sslConfig=/etc/ssl/openssl.cnf;; 7 | Darwin*) sslConfig=/System/Library/OpenSSL/openssl.cnf;; 8 | esac 9 | openssl req \ 10 | -newkey rsa:2048 \ 11 | -x509 \ 12 | -nodes \ 13 | -keyout server.key \ 14 | -new \ 15 | -out server.pem \ 16 | -subj /CN=localhost \ 17 | -reqexts SAN \ 18 | -extensions SAN \ 19 | -config <(cat $sslConfig \ 20 | <(printf '[SAN]\nsubjectAltName=DNS:localhost')) \ 21 | -sha256 \ 22 | -days 3650 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /dockerNginxHacking/readme.md: -------------------------------------------------------------------------------- 1 | #### Hacking Nginx as reverse proxy 2 | 3 | ##### Create a local file called nginx.conf 4 | 5 | Add this: 6 | 7 | ``` 8 | events { 9 | worker_connections 1024; 10 | } 11 | 12 | http { 13 | server { 14 | listen 8000; 15 | server_name localhost; 16 | location / { 17 | proxy_pass http://oktaproxy.com; 18 | } 19 | } 20 | } 21 | ``` 22 | 23 | ##### Run Docker with this command: 24 | 25 | ``` 26 | docker run -it -p 80:8000 -v "$PWD":/etc/nginx nginx /bin/bash -c "nginx ; bash" 27 | ``` 28 | ##### Then Connect to `http://localhost:80` 29 | 30 | You should see Oktaproxy running on your local machine 31 | 32 | 33 | -------------------------------------------------------------------------------- /amazonLambdaUpload/readme.md: -------------------------------------------------------------------------------- 1 | ### Upload Lambda function to AWS 2 | 3 | Assuming you have the CLI installed and setup: 4 | 5 | ``` 6 | aws lambda create-function \ 7 | --region us-east-1 \ 8 | --function-name deletemeNOW \ 9 | --zip-file fileb://./file.zip \ 10 | --runtime go1.x \ 11 | --tracing-config Mode=Active \ 12 | --role arn:aws:iam::761861444952:role/wef_lambda_function \ 13 | --handler index 14 | 15 | NODE Version 16 | 17 | aws lambda create-function --region us-east-1 --function-name deletemeNOW --zip-file fileb://./file.zip --runtime nodejs4.3 --tracing-config Mode=Active --role arn:aws:iam::761861444952:role/wef_lambda_function --handler index.handler 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /awsLambdaTest/readme.md: -------------------------------------------------------------------------------- 1 | ### Testing Lambdas locally 2 | 3 | #### Uploading and testing lambdas is a pain. 4 | 5 | I am using lambda-local https://www.npmjs.com/package/lambda-local 6 | 7 | **Install it like this:** `npm install -g lambda-local` 8 | 9 | They have examples on their website, but here is a basic one that works, 10 | it is based on the stock lambda that Amazon Creates for you 11 | 12 | `lambda-local -l index.js -h handler -e event.json` 13 | 14 | when it's done, if you copy my source, you will see this: 15 | 16 | ``` 17 | info: START RequestId: 9f9f5113-b335-d115-4aa8-06e08ab63e89 18 | info: End - Message 19 | info: ------ 20 | info: Hello from Lambda 21 | info: ------ 22 | info: Lambda successfully executed in 7ms. 23 | ``` 24 | -------------------------------------------------------------------------------- /dockerSnapshot/readme.md: -------------------------------------------------------------------------------- 1 | ### How to take a snapshot in Docker 2 | 3 | Once you have your Docker Image setup, and you want to SnapShot it. 4 | 5 | Press **CTRL + P**, then **CTRL+Q** 6 | 7 | Then run: 8 | 9 | `docker ps` 10 | 11 | This will show you the Container ID that is running. 12 | 13 | Then run: 14 | 15 | `docker commit 451d643f8dd0 mybackup` 16 | 17 | To restart your images run: 18 | 19 | `docker run –it mybackup bash` 20 | 21 | If you want to attach your console to an image that is running, you can use 22 | 23 | `docker attach 451d643f8dd0` <-This is the ID of the running container 24 | 25 | For example, you can reattach to your running image after you snapshot 26 | 27 | To start up your snapshot again, at any time just run it like so 28 | 29 | `docker run –it mybackup bash` 30 | 31 | -------------------------------------------------------------------------------- /awsAnythingGoesAuthorizer/denyAnything.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const generatePolicy = function(principalId, effect, resource) { 4 | const authResponse = {}; 5 | authResponse.principalId = principalId; 6 | if (effect && resource) { 7 | const policyDocument = {}; 8 | policyDocument.Version = '2012-10-17'; 9 | policyDocument.Statement = []; 10 | const statementOne = {}; 11 | statementOne.Action = 'execute-api:Invoke'; 12 | statementOne.Effect = effect; 13 | statementOne.Resource = resource; 14 | policyDocument.Statement[0] = statementOne; 15 | authResponse.policyDocument = policyDocument; 16 | } 17 | return authResponse; 18 | }; 19 | 20 | module.exports.authorizer = (event, context, callback) => { 21 | 22 | callback(null, generatePolicy('user123', 'Deny', event.methodArn)); 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /awsAnythingGoesAuthorizer/allowAnything.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const generatePolicy = function(principalId, effect, resource) { 4 | const authResponse = {}; 5 | authResponse.principalId = principalId; 6 | if (effect && resource) { 7 | const policyDocument = {}; 8 | policyDocument.Version = '2012-10-17'; 9 | policyDocument.Statement = []; 10 | const statementOne = {}; 11 | statementOne.Action = 'execute-api:Invoke'; 12 | statementOne.Effect = effect; 13 | statementOne.Resource = resource; 14 | policyDocument.Statement[0] = statementOne; 15 | authResponse.policyDocument = policyDocument; 16 | } 17 | return authResponse; 18 | }; 19 | 20 | module.exports.authorizer = (event, context, callback) => { 21 | 22 | callback(null, generatePolicy('user123', 'Allow', event.methodArn)); 23 | 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /awsSam/TestAuthorizerFunc/lambda_function.py: -------------------------------------------------------------------------------- 1 | def generate_policy(principal_id, effect=None, resource=None): 2 | auth_response = { 3 | 'principalId': principal_id 4 | } 5 | 6 | if effect and resource: 7 | auth_response['policyDocument'] = { 8 | 'Version': '2012-10-17', 9 | 'Statement': [ 10 | { 11 | 'Action': 'execute-api:Invoke', 12 | 'Effect': effect, 13 | 'Resource': resource 14 | } 15 | ] 16 | } 17 | 18 | return auth_response 19 | 20 | 21 | 22 | 23 | def lambda_handler(event, context): 24 | token = event['authorizationToken'] 25 | method_arn = event['methodArn'] 26 | print(f"Client token: {token}") 27 | print(f"Method ARN: {method_arn}") 28 | 29 | if token == 'Bearer a.b.c': 30 | return generate_policy(token, 'Allow', method_arn) 31 | else: 32 | raise Exception('Unauthorized') 33 | -------------------------------------------------------------------------------- /awsSam/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | 6 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 7 | 8 | if [ -z "$S3_BUCKET" ]; then 9 | echo "Missing S3_BUCKET and STACK_NAME" 10 | echo $USE_MSG 11 | exit 1 12 | fi 13 | 14 | if [ -z "$STACK_NAME" ]; then 15 | echo "Missing STACK_NAME" 16 | echo $USE_MSG 17 | exit 1 18 | fi 19 | 20 | # zip up functionZZ 21 | #zip api-proxy-lambda.zip index.js 22 | 23 | # upload zip to S3 24 | sam package --template-file 03-sam-swagger-auth-template.yaml --s3-bucket $S3_BUCKET --output-template-file output.yaml 25 | 26 | # deploy to cloud formation 27 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 28 | 29 | # get API endpoint 30 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 31 | 32 | # remove quotes 33 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 34 | 35 | echo "Test in browser: $API_ENDPOINT" 36 | 37 | 38 | -------------------------------------------------------------------------------- /angularNotes/readme.md: -------------------------------------------------------------------------------- 1 | ### Angular notes 2 | 3 | **Start New Project**Hello from Lambda@Edge!
19 | 20 | 21 | `; 22 | 23 | exports.handler = (event, context, callback) => { 24 | /* 25 | * Generate HTTP OK response using 200 status code with HTML body. 26 | */ 27 | const response = { 28 | status: '200', 29 | statusDescription: 'OK', 30 | headers: { 31 | 'cache-control': [{ 32 | key: 'Cache-Control', 33 | value: 'max-age=100' 34 | }], 35 | 'content-type': [{ 36 | key: 'Content-Type', 37 | value: 'text/html' 38 | }], 39 | 'content-encoding': [{ 40 | key: 'Content-Encoding', 41 | value: 'UTF-8' 42 | }], 43 | }, 44 | body: content, 45 | }; 46 | callback(null, response); 47 | }; 48 | 49 | ``` 50 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | S3_BUCKET=$1 4 | STACK_NAME=$2 5 | TEMPLATE_FILE=$3 6 | 7 | #rm output.yaml 8 | #aws cloudformation delete-stack --stack-name swagger03 9 | 10 | 11 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 12 | 13 | if [ -z "$S3_BUCKET" ]; then 14 | echo "Missing S3_BUCKET and STACK_NAME" 15 | echo $USE_MSG 16 | exit 1 17 | fi 18 | 19 | if [ -z "$STACK_NAME" ]; then 20 | echo "Missing STACK_NAME" 21 | echo $USE_MSG 22 | exit 1 23 | fi 24 | 25 | if [ -z "$TEMPLATE_FILE" ]; then 26 | echo "Missing TEMPLATE_FILE" 27 | echo $USE_MSG 28 | exit 1 29 | fi 30 | 31 | # upload to S3 32 | sam package --template-file $TEMPLATE_FILE --s3-bucket $S3_BUCKET --output-template-file output.yaml 33 | 34 | # deploy to cloud formation 35 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM $4 $5 $6 $7 36 | 37 | # get API endpoint 38 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 39 | 40 | # remove quotes 41 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 42 | 43 | echo "" 44 | echo "Test in browser: $API_ENDPOINT" 45 | 46 | echo "" 47 | echo "To Delete the Stack use this command" 48 | echo "aws cloudformation delete-stack --stack-name $STACK_NAME &" 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /phpDecodeJwt/readme.md: -------------------------------------------------------------------------------- 1 | ## Poor mans JWT decode.. (Not Verify) 2 | 3 | This is the code I use to decode a JWT from 64encoded to object in PHP 4 | 5 | ``` 6 | Middle Segment !"; 13 | 14 | echo $tokenSegments[1]; echo ""+val.title+"
](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=myteststack&templateURL=https://awscomputeblogimages.s3-us-west-2.amazonaws.com/samfarm-website.yaml)
43 | ```
44 |
45 | #### It will look like this Now !
46 |
47 | *----- SAMPLE -----*
48 |
49 | [
](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=myteststack&templateURL=https://awscomputeblogimages.s3-us-west-2.amazonaws.com/samfarm-website.yaml)
50 |
51 | *----- SAMPLE -----*
52 |
53 | Hope this helps someone
--------------------------------------------------------------------------------
/oktaMultipleLoginPage/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Hello from Lambda@Edge!
21 | 22 | 23 | `; 24 | 25 | exports.handler = (event, context, callback) => { 26 | /* 27 | * Generate HTTP OK response using 200 status code with HTML body. 28 | */ 29 | 30 | // console.log(event) 31 | 32 | const request = event.Records[0].cf.request; 33 | const headers = request.headers; 34 | var resultr = "" 35 | 36 | console.log ("in lambda"); 37 | 38 | if (headers.cookie) { 39 | console.log("in 30") 40 | 41 | for (let i = 0; i < headers.cookie.length; i++) { 42 | if (headers.cookie[i].value.indexOf("jwt") >= 0) { 43 | console.log('on line 26'); 44 | resultr="You have a cookie on line 26" 45 | break; 46 | } else { 47 | console.log("Not on line 26, on line 29") 48 | } 49 | } 50 | } else { 51 | resultr="You have No cookie, I gave you one" 52 | 53 | console.log("No Cookie :") 54 | 55 | } 56 | 57 | 58 | 59 | const response = { 60 | status: '200', 61 | statusDescription: 'OK', 62 | headers: { 63 | 'cache-control': [{ 64 | key: 'Cache-Control', 65 | value: 'max-age=100' 66 | }], 67 | 'content-type': [{ 68 | key: 'Content-Type', 69 | value: 'text/html' 70 | }], 71 | 'content-encoding': [{ 72 | key: 'Content-Encoding', 73 | value: 'UTF-8' 74 | }], 75 | 'set-cookie': [{ 76 | key: 'Set-Cookie', 77 | value: `jwt=eyJraWQiOiJkZFBVRER5VXBIMk41d0dTWHZucVFaeS1PbVRGU1Z1NVBZYW5zanBzb0FzIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIwMHUxOGVlaHUzNDlhUzJ5WDFkOCIsIm5hbWUiOiJva3RhcHJveHkgb2t0YXByb3h5IiwidmVyIjoxLCJpc3MiOiJodHRwczovL2NvbXBhbnl4Lm9rdGEuY29tIiwiYXVkIjoidlpWNkNwOHJuNWx4ck45YVo2ODgiLCJpYXQiOjE1MjM5MTMyNTgsImV4cCI6MTUyMzkxNjg1OCwianRpIjoiSUQuMW1Od0xSbEQ4X2ZsLUFfMHN4QzdIZTVIdVU4Zm0xQU1DR0dsU2ZjelltTSIsImFtciI6WyJwd2QiXSwiaWRwIjoiMDBveTc0YzBnd0hOWE1SSkJGUkkiLCJub25jZSI6Im4tMFM2X1d6QTJNaiIsInByZWZlcnJlZF91c2VybmFtZSI6Im9rdGFwcm94eUBva3RhLmNvbSIsImF1dGhfdGltZSI6MTUyMzkxMzI1MywiYXRfaGFzaCI6IllPX0J1MWMxRGxkbEdieHJWdHZSZkEifQ.MfkLPHevfEaLjM1FZh6vIFcBVuUFx0PqTxSia0X54OQhaJdvu0OOT8YtLrqUcqIlywwcYKtKRP5XBLSFAuphWbAJGvf1wPK_kJBRYTINi4264Ta1EtNC9BM_lcUitWTV0yNNDGNbpCOYBlO-LqOJB4VLOmXswbo6QGj36TujgChRZclG5w25s2SCj6si_TsgvDKsQX0k-eaAgziBSu0APRyVwEl0xiGukfNYD1bdVTjz0Q_UykX2fnzI6Y_Tw__A5_e-ZPy4bgH0tigFYut9yJP-Yf4aomY7xS95Y_89bDQStHtJGxLMFrWL6fq4wrwufOOe_rg9dok8kVUTUUDgjQ; Path=/` 78 | }], 79 | }, 80 | body: resultr, 81 | }; 82 | callback(null, response); 83 | }; 84 | 85 | ``` 86 | 87 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: Yes you can use SAM to create an Authorizer 4 | Parameters: 5 | Environment: 6 | Type: String 7 | Default: dev 8 | StageName: 9 | Type: String 10 | Default: prod 11 | Description: The Lambda Function and API Gateway Stage 12 | 13 | Outputs: 14 | ExampleAPIUrl: 15 | Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/" 16 | 17 | Resources: 18 | HelloAPI: 19 | Type: AWS::Serverless::Api 20 | Properties: 21 | StageName: !Sub ${Environment} 22 | DefinitionBody: 23 | swagger: 2.0 24 | info: 25 | title: 26 | Ref: AWS::StackName 27 | securityDefinitions: 28 | test-authorizer: 29 | type: apiKey 30 | name: Authorization 31 | in: header 32 | x-amazon-apigateway-authtype: custom 33 | x-amazon-apigateway-authorizer: 34 | type: token 35 | authorizerUri: 36 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthorizerFunc.Arn}/invocations 37 | authorizerResultTtlInSeconds: 5 38 | paths: 39 | /vehicles: 40 | get: 41 | x-amazon-apigateway-integration: 42 | httpMethod: POST 43 | type: aws_proxy 44 | uri: 45 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations 46 | responses: {} 47 | security: 48 | - test-authorizer: [] 49 | /bookings: 50 | get: 51 | x-amazon-apigateway-integration: 52 | httpMethod: POST 53 | type: aws_proxy 54 | uri: 55 | !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${BookingsLambda.Arn}/invocations 56 | responses: {} 57 | VehiclesLambda: 58 | Type: AWS::Serverless::Function 59 | Properties: 60 | FunctionName: !Sub VehiclesLambda-${Environment} 61 | Handler: index.handler 62 | Runtime: nodejs4.3 63 | CodeUri: vehicles 64 | MemorySize: 128 65 | Timeout: 30 66 | Policies: 67 | - AWSLambdaBasicExecutionRole 68 | - AmazonDynamoDBFullAccess 69 | Events: 70 | MyEndpoint: 71 | Type: Api 72 | Properties: 73 | Path: /vehicles 74 | Method: GET 75 | RestApiId: 76 | Ref: HelloAPI 77 | 78 | BookingsLambda: 79 | Type: AWS::Serverless::Function 80 | Properties: 81 | FunctionName: !Sub BookingsLambda-${Environment} 82 | Handler: index.handler 83 | Runtime: nodejs4.3 84 | CodeUri: bookings 85 | MemorySize: 128 86 | Timeout: 30 87 | Policies: 88 | - AWSLambdaBasicExecutionRole 89 | - AmazonDynamoDBFullAccess 90 | Events: 91 | MyEndpoint: 92 | Type: Api 93 | Properties: 94 | Path: /bookings 95 | Method: GET 96 | RestApiId: 97 | Ref: HelloAPI 98 | 99 | AuthorizerFunc: 100 | Type: AWS::Serverless::Function 101 | Properties: 102 | Handler: authorizer.authorizer 103 | Runtime: nodejs4.3 104 | CodeUri: ./authorizer 105 | 106 | AuthorizerFuncPerm: 107 | Type: AWS::Lambda::Permission 108 | DependsOn: 109 | - HelloAPI 110 | - AuthorizerFunc 111 | Properties: 112 | Action: lambda:InvokeFunction 113 | FunctionName: 114 | Ref: AuthorizerFunc 115 | Principal: apigateway.amazonaws.com 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/setups3bucket/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var AWS = require('aws-sdk'); 4 | var fs = require('fs'); 5 | var s3 = new AWS.S3(); 6 | var response = require ('cfn-response') 7 | 8 | var oktaOrg = "" 9 | var myBucket = "" 10 | var myKey = 'index.html'; 11 | 12 | 13 | let createS3Bucket = function(bucketname, callback) { 14 | return new Promise(function(resolve, reject) { 15 | s3.createBucket({ Bucket: bucketname, ACL: 'public-read' }, function(err, data) { 16 | if (err) { 17 | console.log(err) 18 | 19 | if (err.code == "BucketAlreadyExists") { //no sweat.. already there 20 | resolve() 21 | } 22 | else { //maybe bucketname didn't meet requirements ? 23 | reject ( err ) 24 | } 25 | } else { 26 | resolve () 27 | } 28 | }); 29 | 30 | }); 31 | } 32 | 33 | let createIndexFile = function(nameOfBucket, nameOfFile, callback) { 34 | return new Promise(function(resolve, reject) { 35 | var fileBuffer = fs.readFileSync("oktaLoginPage.html"); 36 | var metaData = 'text/html'; 37 | 38 | var fileString = fileBuffer.toString() 39 | fileString = fileString.replace( "{oktaOrg}","https://"+oktaOrg) 40 | var buf = Buffer.from(fileString, 'utf-8'); 41 | 42 | s3.putObject({ 43 | ACL: 'public-read', 44 | Bucket: nameOfBucket, 45 | Key: nameOfFile, 46 | Body: buf, 47 | ContentType: metaData 48 | }, function(error, response2) { 49 | resolve('done') 50 | 51 | }); 52 | }) 53 | } 54 | 55 | let deleteS3Bucket = function(bucketname, callback) { 56 | return new Promise(function(resolve, reject) { 57 | var params = { 58 | Bucket: bucketname, 59 | Delete: { // required 60 | Objects: [ // required 61 | { 62 | Key: myKey // required 63 | } 64 | ], 65 | }, 66 | }; 67 | 68 | s3.deleteObjects(params, function(err, data) { 69 | if (err) { 70 | if ( err.code == "NoSuchBucket") { // No sweat, bucket doesn't exist 71 | resolve() 72 | } 73 | else { 74 | callback(err) 75 | 76 | } 77 | } 78 | else { 79 | console.log("File gone"); 80 | s3.deleteBucket({Bucket: myBucket}, function (err, data) { 81 | if (err) { 82 | callback ( err ) 83 | } else { 84 | resolve () // All good 85 | } 86 | }); 87 | 88 | } // successful response 89 | }); 90 | 91 | }); 92 | } 93 | 94 | 95 | 96 | exports.handler = (event, context, callback) => { 97 | 98 | myBucket=event.ResourceProperties['bucketname'] 99 | oktaOrg=event.ResourceProperties['oktaOrg'] 100 | 101 | if (event.RequestType == 'Create') { 102 | 103 | createS3Bucket(myBucket, callback).then(function () { 104 | createIndexFile(myBucket, "index.html").then ( function() { 105 | response.send(event, context, response.SUCCESS, {"1":"1"}); 106 | 107 | }).catch( function(err) { 108 | response.send(event, context, response.FAILED, {"1":"1"}); 109 | 110 | }) 111 | }) 112 | } 113 | 114 | else if (event.RequestType == 'Delete') { 115 | deleteS3Bucket(myBucket, callback).then(function () { 116 | response.send(event, context, response.SUCCESS, {"1":"1"}); 117 | }) 118 | } 119 | }; 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /awsCloudformationMakeBucket/setups3bucket/oktaLoginPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /loginWidgetJsfiddle/readme.md: -------------------------------------------------------------------------------- 1 | # I started experimenting running the Okta Login widet with JSFiddle, this 2 | worked for me, just change your ClientID and Org. 3 | 4 | ``` 5 | 6 | 7 | 10 | 11 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 27 | 28 | 29 | 30 | 31 | 154 | 155 | 156 | 157 | `` 158 | 159 | -------------------------------------------------------------------------------- /awsSamOktaRental/vehicles/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var inventory= { 4 | "inventory": [ 5 | { "id":"112345", "make":"Jeep", "model":"Wrangler", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, 4x4, Removable Top, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80jes162b021001.png" }, 6 | { "id":"122346", "make":"Ford", "model":"Explorer", "class":"SUV", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"55", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80fos101a021001.png" }, 7 | { "id":"123347", "make":"Subaru", "model":"Forester", "class":"SUV", "desc":"Radio, CD, AWD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70sus041f021001.png" }, 8 | { "id":"544321", "make":"Honda", "model":"Accord", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"25", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80hoc011e021001_2.png" }, 9 | { "id":"545321", "make":"Mercedes-Benz", "model":"AMG C 43", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"125", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70mbcbg5a021001.png" }, 10 | { "id":"546321", "make":"Cadillac", "model":"ATS-V", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"95", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc60cac222a021001.png" }, 11 | { "id":"547321", "make":"Chevrolet", "model":"Cruze", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering", "price":"15", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70chc302b021001.png" }, 12 | { "id":"123845", "make":"Toyota", "model":"Tundra", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"65", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80tot109e021001.png" }, 13 | { "id":"123946", "make":"Buick", "model":"Encore", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70bus041a021001.png" }, 14 | { "id":"123479", "make":"Audi", "model":"S3", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"72", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70auc321a021001.png" }, 15 | { "id":"543218", "make":"Toyota", "model":"Prius c", "class":"Midsize", "desc":"Hybrid, Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70toc251b021001.png" }, 16 | { "id":"754321", "make":"Volkswagen", "model":"Volkswagen Tiguan", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"75", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80vws031b021001.png" }, 17 | { "id":"654321", "make":"Bentley", "model":"Bentley Flying Spur", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"356", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/main/USC50BEC111B021001.png" }, 18 | { "id":"254321", "make":"Toyota", "model":"Camry", "class":"Midsize", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80toc021b021001.png" } 19 | ] 20 | } 21 | 22 | var response = { 23 | statusCode: 200, 24 | body: JSON.stringify(inventory), 25 | "isBase64Encoded": false 26 | }; 27 | console.log("response: " + JSON.stringify(response)) 28 | callback(null, response); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /awsOktaRentalWithAuthorizer/vehicles/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | 3 | var inventory= { 4 | "inventory": [ 5 | { "id":"112345", "make":"Jeep", "model":"Wrangler", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, 4x4, Removable Top, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80jes162b021001.png" }, 6 | { "id":"122346", "make":"Ford", "model":"Explorer", "class":"SUV", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"55", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80fos101a021001.png" }, 7 | { "id":"123347", "make":"Subaru", "model":"Forester", "class":"SUV", "desc":"Radio, CD, AWD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering\n", "price":"35", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70sus041f021001.png" }, 8 | { "id":"544321", "make":"Honda", "model":"Accord", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering\n", "price":"25", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80hoc011e021001_2.png" }, 9 | { "id":"545321", "make":"Mercedes-Benz", "model":"AMG C 43", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"125", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70mbcbg5a021001.png" }, 10 | { "id":"546321", "make":"Cadillac", "model":"ATS-V", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"95", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc60cac222a021001.png" }, 11 | { "id":"547321", "make":"Chevrolet", "model":"Cruze", "class":"Midsize", "desc":"CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Dual Mirrors, Power Brakes, Power Driver Seat, Power Mirrors, Power Steering, Power Windows, Tilt Steering", "price":"15", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70chc302b021001.png" }, 12 | { "id":"123845", "make":"Toyota", "model":"Tundra", "class":"Offroad", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"65", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80tot109e021001.png" }, 13 | { "id":"123946", "make":"Buick", "model":"Encore", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70bus041a021001.png" }, 14 | { "id":"123479", "make":"Audi", "model":"S3", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"72", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70auc321a021001.png" }, 15 | { "id":"543218", "make":"Toyota", "model":"Prius c", "class":"Midsize", "desc":"Hybrid, Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"45", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc70toc251b021001.png" }, 16 | { "id":"754321", "make":"Volkswagen", "model":"Volkswagen Tiguan", "class":"SUV", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Mirrors, Power Windows, Tilt Steering, V8 Engine", "price":"75", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80vws031b021001.png" }, 17 | { "id":"654321", "make":"Bentley", "model":"Bentley Flying Spur", "class":"Premium", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Bucket Seats, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Navigational System, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"356", "avail":"false", "image_url":"https://www.cstatic-images.com/car-pictures/main/USC50BEC111B021001.png" }, 18 | { "id":"254321", "make":"Toyota", "model":"Camry", "class":"Midsize", "desc":"Radio, CD, Anti-Theft Device, Anti-Skid Device, Central Locking, Cruise Control, Driver Airbag, Dual Airbags, Power Driver Seat, Power Mirrors, Power Windows, Tilt Steering", "price":"35", "avail":"true", "image_url":"https://www.cstatic-images.com/car-pictures/xl/usc80toc021b021001.png" } 19 | ] 20 | } 21 | 22 | var response = { 23 | statusCode: 200, 24 | body: JSON.stringify(inventory), 25 | "isBase64Encoded": false 26 | }; 27 | console.log("response: " + JSON.stringify(response)) 28 | callback(null, response); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /awsSam/readme.md: -------------------------------------------------------------------------------- 1 | ##### Start local API Gateway: 2 | 3 | `sam local start-api` 4 | 5 | ##### Before deployment, make bucket: (Make Bucket) 6 | 7 | `aws s3 mb s3://bucket-name` 8 | 9 | ##### Package: 10 | 11 | `sam package --template-file template.yaml --s3-bucket [your_s3_bucket] --output-template-file package.yaml` 12 | 13 | **Note, drop the s3:// prefix before packaging** *(Wasn't so obvious to me)* 14 | 15 | `sam deploy --template-file package.yaml --stack-name serverless-application --capabilities CAPABILITY_IAM` 16 | 17 | ##### To remove the stack, run the following command: 18 | 19 | `aws cloudformation delete-stack --stack-name serverless-application` 20 | 21 | ##### Nice Example of script that does it all for you: 22 | 23 | Honestly, this deployment was pretty rough to get going.. Here is a working example of what i used to deploy an API Gateway with an Authorizer. I'll show the deployment script, then the SAM Template *(Thanks Brent)* 24 | 25 | #### Sample Template 26 | 27 | ``` 28 | AWSTemplateFormatVersion: '2010-09-09' 29 | Transform: AWS::Serverless-2016-10-31 30 | Description: An example serverless "Hello World2 " application with a custom authorizer. 31 | 32 | Parameters: 33 | AutoPublishAliasName: 34 | Type: String 35 | Default: current 36 | Description: The alias used for Auto Publishing 37 | StageName: 38 | Type: String 39 | Default: prod 40 | Description: The Lambda Function and API Gateway Stage 41 | FunctionName: 42 | Type: String 43 | Default: Example 44 | Description: The Lambda Function Name 45 | 46 | Outputs: 47 | ExampleAPIUrl: 48 | Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/" 49 | 50 | Resources: 51 | ApiGateway: 52 | Type: AWS::Serverless::Api 53 | Properties: 54 | StageName: Prod 55 | DefinitionBody: 56 | swagger: 2.0 57 | info: 58 | title: 59 | Ref: AWS::StackName 60 | securityDefinitions: 61 | test-authorizer: 62 | type: apiKey 63 | name: Authorization 64 | in: header 65 | x-amazon-apigateway-authtype: custom 66 | x-amazon-apigateway-authorizer: 67 | type: token 68 | authorizerUri: 69 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${TestAuthorizerFunc.Arn}/invocations 70 | authorizerResultTtlInSeconds: 5 71 | paths: 72 | "/": 73 | get: 74 | x-amazon-apigateway-integration: 75 | httpMethod: post 76 | type: aws_proxy 77 | uri: 78 | Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorld.Arn}/invocations 79 | responses: {} 80 | security: 81 | - test-authorizer: [] 82 | 83 | HelloWorld: 84 | Type: AWS::Serverless::Function 85 | Properties: 86 | Handler: lambda_function.lambda_handler 87 | Runtime: python3.6 88 | CodeUri: ./HelloWorld 89 | Events: 90 | GetApi: 91 | Type: Api 92 | Properties: 93 | Path: / 94 | Method: get 95 | RestApiId: 96 | Ref: ApiGateway 97 | 98 | TestAuthorizerFunc: 99 | Type: AWS::Serverless::Function 100 | Properties: 101 | Handler: lambda_function.lambda_handler 102 | Runtime: python3.6 103 | CodeUri: ./TestAuthorizerFunc 104 | 105 | TestAuthorizerFuncPerm: 106 | Type: AWS::Lambda::Permission 107 | DependsOn: 108 | - ApiGateway 109 | - TestAuthorizerFunc 110 | Properties: 111 | Action: lambda:InvokeFunction 112 | FunctionName: 113 | Ref: TestAuthorizerFunc 114 | Principal: apigateway.amazonaws.com 115 | 116 | ``` 117 | 118 | #### Deploy.sh (This script rocks!, I forgot who wrote it, thank you though) 119 | 120 | ``` 121 | #!/bin/bash 122 | 123 | S3_BUCKET=$1 124 | STACK_NAME=$2 125 | 126 | USE_MSG="Usage: deploy.sh S3_BUCKET STACK_NAME" 127 | 128 | if [ -z "$S3_BUCKET" ]; then 129 | echo "Missing S3_BUCKET and STACK_NAME" 130 | echo $USE_MSG 131 | exit 1 132 | fi 133 | 134 | if [ -z "$STACK_NAME" ]; then 135 | echo "Missing STACK_NAME" 136 | echo $USE_MSG 137 | exit 1 138 | fi 139 | 140 | # zip up functionZZ 141 | #zip api-proxy-lambda.zip index.js 142 | 143 | # upload zip to S3 144 | sam package --template-file 03-sam-swagger-auth-template.yaml --s3-bucket $S3_BUCKET --output-template-file output.yaml 145 | 146 | # deploy to cloud formation 147 | sam deploy --template-file output.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM 148 | 149 | # get API endpoint 150 | API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[0].OutputValue') 151 | 152 | # remove quotes 153 | API_ENDPOINT=$(sed -e 's/^"//' -e 's/"$//' <<< $API_ENDPOINT) 154 | 155 | echo "Test in browser: $API_ENDPOINT" 156 | 157 | 158 | ``` 159 | 160 | #### This is what it outputs when it is done 161 | 162 | ``` 163 | ./deploy.sh okta914 okta914 164 | A newer version of the AWS SAM CLI is available! 165 | Your version: 0.2.11 166 | Latest version: 0.3.0 167 | See https://github.com/awslabs/aws-sam-local for upgrade instructions 168 | 169 | Uploading to 5392c0189bd17e63977147a23dc64381 334 / 334.0 (100.00%) 170 | Successfully packaged artifacts and wrote output template to file output.yaml. 171 | Execute the following command to deploy the packaged template 172 | aws cloudformation deploy --template-file /private/tmp/sam4/Serverless-Hello-World/hello-world/output.yaml --stack-name