Skip to content

Instantly share code, notes, and snippets.

View dsandor's full-sized avatar

David Sandor dsandor

View GitHub Profile
exports.authorizerHandler = async (event, context, callback) => {
if (event.headers['Authorization'] && event.headers['Authorization'] !== 'fail') {
callback(null, generatePolicy('user', 'Allow', event.methodArn));
} else {
callback(null, generatePolicy('user', 'Deny', event.methodArn));
}
};
RequestAuthorizerFunction:
Type: AWS::Serverless::Function
Properties:
Policies:
- AWSLambdaVPCAccessExecutionRole
CodeUri: ./
Handler: index.authorizerHandler
Runtime: nodejs12.x
HelloWorldApi:
Type: AWS::Serverless::Api
Properties:
Name: hello-world-api
StageName: v1
MethodSettings:
- LoggingLevel: INFO
ResourcePath: '/*' # allows logging on any resource
HttpMethod: '*' # allows logging on all methods
Cors:
@dsandor
dsandor / template.yaml
Last active February 26, 2020 14:52
Working API Gateway Lambda Request Authorizer
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
hello-world-api
API example of using a request authorizer with API Gateway.
Globals:
Function:
Timeout: 120
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "2020-01-03T15:11:20.855Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "AWS:AAAAAAAAAAAAAAAAAAAAA"
module.exports.handler = (event) => {
console.log('event:\n', JSON.stringify(event));
};
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
MemorySize: 128
Timeout: 15
Resources:
# S3 Bucket
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
MemorySize: 128
Timeout: 15
Resources:
# Permissions
@dsandor
dsandor / template.yaml
Created January 2, 2020 20:58
SAM Template to connect a Lambda up to an S3 file event.
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
MemorySize: 128
Timeout: 15
Resources:
# Roles

Keybase proof

I hereby claim:

  • I am dsandor on github.
  • I am dsandor (https://keybase.io/dsandor) on keybase.
  • I have a public key ASCmCwOje9FkvgCByw49ng6RysmaFVUJLKfp9qLvoEfvQgo

To claim this, I am signing this object: