Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris McKinnel chrismckinnel

View GitHub Profile
View .bashrc
# Function to automatically call cfn-lint when deploying AWS CloudFormation templates
function aws() {
export COMMAND=$@
if [[ $COMMAND == cloudformation\ create-stack* ]] || [[ $COMMAND == cloudformation\ update-stack* ]];
then
while [[ $# -gt 0 ]]
do
key="$1"
View lambda-edge-step-dir-2
├── .aws-sam
│ └── build
│ ├── RedirectLambda
│ │ ├── RedirectLambda.js
│ │ └── package.json
│ └── template.yaml
├── lambda-edge-prerequisites.yaml
├── lambda-edge.yaml
├── lambdas
│ ├── RedirectLambda.js
View lambda-edge-step-dir-1
├── lambda-edge-prerequisites.yaml
├── lambda-edge.yaml
├── lambdas
│ ├── RedirectLambda.js
│ └── package.json
└── packaged
└── lambda-edge.yaml
View lambda-edge-step-full
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Full stack to demo Lambda@Edge for CloudFront redirects
Parameters:
RedirectLambdaName:
Type: String
Default: redirect-lambda
Resources:
View lambda-edge-step-9
CloudFront:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
Compress: true
ForwardedValues:
QueryString: true
TargetOriginId: google-origin
ViewerProtocolPolicy: redirect-to-https
View lambda-edge-step-8
{
"name": "lambda-redirect",
"version": "1.0.1",
"description": "Redirect lambda using Lambda@Edge and CloudFront",
"author": "Chris McKinnel",
"license": "MIT"
}
View lambda-edge-step-7
'use strict';
exports.handler = async (event) => {
console.log('Event: ', JSON.stringify(event, null, 2));
let request = event.Records[0].cf.request;
const redirects = {
'/path-1': 'https://consegna.cloud/',
'/path-2': 'https://www.amazon.com/',
};
View lambda-edge-step-5
RedirectLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/
FunctionName: !Ref RedirectLambdaName
Handler: RedirectLambda.handler
Role: !GetAtt RedirectLambdaFunctionRole.Arn
Runtime: nodejs10.x
AutoPublishAlias: live
View lambda-edge-step-4
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Full stack to demo Lambda@Edge for CloudFront redirects
Parameters:
RedirectLambdaName:
Type: String
Default: redirect-lambda
Resources:
View lambda-edge-step-1
AWSTemplateFormatVersion: '2010-09-09'
Resources:
RedirectLambdaBucket:
Type: AWS::S3::Bucket
Outputs:
RedirectLambdaBucketName:
Description: Redirect lambda package S3 bucket name
Value: !Ref RedirectLambdaBucket