Skip to content

Instantly share code, notes, and snippets.

View georgmao's full-sized avatar

AWSGeorge georgmao

View GitHub Profile
@georgmao
georgmao / apigwMultiApiSpecs.yaml
Last active April 27, 2021 02:45
A basic SAM Template for an API that uses DefinitionBody and multiple OpenApi specs
# Create a HttpApi with a YAML OpenAPI Spec
# Use Tranform Includes to dynamically import parts of the API via OpenAPI Specs
Type: AWS::Serverless::HttpApi or #AWS::Serverless::Api (REST APIs)
Properties:
DefinitionBody:
openapi: 3.0.1
info:
title: "myAPI-splitspecs"
version: "2019-02-07T22:41:10Z"
@georgmao
georgmao / apigwBasic.yaml
Created April 27, 2021 02:10
A basic SAM Template for an API that uses DefinitionUri OpenApi specs
# Create a HttpApi with a YAML OpenAPI Spec
# Specify a local file path. SAM will replace it with a S3 path and upload for you
# Or you can specify a s3 path directly
Type: AWS::Serverless::HttpApi or #AWS::Serverless::Api (REST APIs)
Properties:
DefinitionUri: ./openapi.yaml or # s3://<mybucket>/<openapi-file-path>
MyTargetTrackingScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: utilization
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref MyScalableTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 0.70 # Any value between 0 and 1 can be used here
# PredefinedMetricSpecification:
# PredefinedMetricType: LambdaProvisionedConcurrencyUtilization
@georgmao
georgmao / layer.js
Last active April 3, 2020 19:06
layers sam template
myFunction:
Type: AWS::Serverless::Function
Properties:
Handler: test.handler
Runtime: nodejs12.x
Timeout: 3
Layers:
- Ref: MyLayer
MyLayer:
@georgmao
georgmao / gist:80c21ca1318cfa477abdcc9bd9031f4b
Last active March 19, 2020 20:09
Lambda response format 1.0
{
"isBase64Encoded": false,
"statusCode": 200,
"body": "Hello from Lambda!",
"headers": {
"Content-Type": "application/json"
}
}
@georgmao
georgmao / cognitoCFnExample.yaml
Created February 26, 2020 13:50
Example CloudFormation template for automated Amazon Cognito Deployments
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
CognitoDomain:
Type: String
MinLength: 3
MaxLength: 63
AllowedPattern: ^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$
Description: Enter a string. Must be alpha numeric 3-63 in length.
@georgmao
georgmao / sampleS3payload.json
Created February 23, 2020 02:58
This is a sample event generated by a S3 put action
{
"Records": [
{
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
@georgmao
georgmao / lambdaLoad.yaml
Created February 18, 2020 01:33
Sample Artillery load test for Lambda using Artillery and sigv4 plugin
config:
target: https://lambda.us-east-2.amazonaws.com
phases:
- duration: 60
arrivalRate: 10
rampTo: 50
plugins:
aws-sigv4:
serviceName: lambda
@georgmao
georgmao / samSecrets.js
Created February 15, 2020 02:20
Sample SAM template using various ways to store secrets
Resources:
ApiFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
# this is a standard lambda env var
user: "This is a regular env var"
# this is a var loaded from SSM
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
# Replace <bucket> with your bucket name
Parameters: