Skip to content

Instantly share code, notes, and snippets.

View singledigit's full-sized avatar

Eric Johnson singledigit

View GitHub Profile
@singledigit
singledigit / vue.config.js
Created July 8, 2019 17:47
Enable preview and live reloading on Cloud9 with Vue-CLI apps
module.exports = {
devServer: {
disableHostCheck: true,
public: 'https://[your cloud9 host id].vfs.cloud9.[region].amazonaws.com'
}
}
@singledigit
singledigit / EventBridgeRule.yaml
Created September 25, 2019 14:25
Using EventBridge rules as events in AWS SAM
TranslateFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: translate/
Timeout: 10
Handler: app.lambdaHandler
Runtime: nodejs10.x
Events:
TranslateEvent:
Type: CloudWatchEvent
@singledigit
singledigit / handler.js
Created October 15, 2019 19:51
Lambda API Gateway Response Handler
const isLocal = process.env.AWS_SAM_LOCAL;
const handlerModel = (body, headers, code) => {
let response = {
'statusCode': code,
'body': JSON.stringify(body)
}
if(headers.length > 0) {
response.headers = response.headers || {};
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: HTTP API test
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
@singledigit
singledigit / 1_instructions.md
Last active April 25, 2020 04:55
Testing a Lambda function locally against DynamoDB on AWS.

Local development with SAM

This method allows you to iterate very quickly against Lambda code without having to run AWS resources locally.

Requirements

Step 1: Create and deploy a simple SAM Template (see template.yaml)

  • must include the environment varibales on the Lambda to pass the SAMPLE_TABLE in (see line 17)
  • use sam deploy --guided for the first time deploy
@singledigit
singledigit / template.yaml
Created August 11, 2020 23:24
Using a DynamoDB CloudFormation resource in a SAM template to add range.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: DDB example
Resources:
Table:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
@singledigit
singledigit / template.yaml
Created August 18, 2020 22:06
Creating an EventBridge rule with API Gateway as the target in AWS SAM
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Event Bridge -> API Gateway
Resources:
RestApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
@singledigit
singledigit / api.yaml
Created September 24, 2020 17:42
Example of an AWS Lambda Destinations configuration for AWS Lambda functions within an application.
# You don't need this, but here it is anyways :)
openapi: "3.0.1"
info:
title: "Translation API (Async)"
version: "1.0.0"
paths:
/:
post:
summary: Create new translation request
@singledigit
singledigit / RequestTemplate-vtl.json
Last active November 6, 2020 18:50
Example of using VTL on Amazon API Gateway to insert an epoch time into Amazon DynamoDB to be used as a TTL field
## This examples converts the millisecond epoch of API Gateway
## to the seconds epoch of DynamoDB and adds 5 minutes for the TTL.
#set( $epoch = $context.requestTimeEpoch / 1000 + 300 )
{
"TableName":"Epoch",
"Item":{
"id":{"S":"$context.requestId"},
"ttlTime":{"N":"$epoch"}
}
@singledigit
singledigit / Activate
Last active February 11, 2021 23:57
Code examples for Serverless Architecture Demo part 3
activate(){
return this.auth.getSession();
}