Skip to content

Commit

Permalink
move login lambda to subdir
Browse files Browse the repository at this point in the history
also:

- fix website title by actually passing it into the site builder lambda
- simplify ./deploy script by sharing code
- make all buckets explicit in ./generate_random_albums script
  • Loading branch information
jpsim committed Jul 1, 2017
1 parent e2a1f51 commit d1da144
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

4 changes: 2 additions & 2 deletions app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ Resources:
Properties:
Handler: index.handler
Runtime: nodejs4.3
CodeUri: dist/lambda.zip
CodeUri: dist/lambda-login.zip
Role: !GetAtt LambdaRole.Arn
Environment:
Variables:
WEBSITE_TITLE: !Ref websiteTitle
WEBSITE_DOMAIN: !Ref website
SESSION_DURATION: !Ref sessionDuration
REDIRECT_ON_SUCCESS: !Ref redirectOnSuccess
Expand Down Expand Up @@ -157,6 +156,7 @@ Resources:
CodeUri: dist/lambda-site-builder.zip
Environment:
Variables:
WEBSITE_TITLE: !Ref websiteTitle
CLOUDFRONT_DISTRIBUTION_DOMAIN:
!GetAtt ProtectedPicturesDistribution.DomainName
ORIGINAL_BUCKET: !Sub
Expand Down
22 changes: 7 additions & 15 deletions deploy
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ fi
output_template_file=$(mktemp)
stackName="ProtectedPictures"

# build Lambda code for Linux
docker build -t "cloudformation-lambda-cookies" .
docker run "cloudformation-lambda-cookies" > dist/lambda.zip

(
cd resize
docker build -t "cloudformation-lambda-resize" .
docker run "cloudformation-lambda-resize" > ../dist/lambda-resize.zip
)

(
cd site-builder
docker build -t "cloudformation-lambda-site-builder" .
docker run "cloudformation-lambda-site-builder" > ../dist/lambda-site-builder.zip
)
for function in login resize site-builder; do
(
cd $function
docker build -t "cloudformation-lambda-$function" .
docker run "cloudformation-lambda-$function" > ../dist/lambda-$function.zip
)
done

# create the target S3 bucket if needed
aws s3 ls ${s3Bucket} > /dev/null
Expand Down
14 changes: 8 additions & 6 deletions generate_random_albums
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

if [ -z "$2" ]; then
echo "Usage:"
echo " generate_random_albums <root bucket> <number of albums>"
echo " generate_random_albums <web bucket> <original bucket> <resized bucket> <number of albums>"
echo "Removes all bucket contents, downloads 6 pictures for each album from unsplash.com, giving each album a random name, uploads them to the original bucket."
exit 1
else
rootBucket=$1
numberOfAlbums=$2
webBucket=$1
originalBucket=$2
resizedBucket=$3
numberOfAlbums=$4
fi

echo "Removing all files in bucket"
for bucket in "$rootBucket" "$rootBucket-original" "$rootBucket-resized"; do
echo "Removing all files in web, original & resized buckets"
for bucket in "$webBucket" "$originalBucket" "$resizedBucket"; do
aws s3 rm --recursive "s3://$bucket" >> /dev/null 2>&1
done

Expand All @@ -27,6 +29,6 @@ for (( albumIndex = 0; albumIndex < ${numberOfAlbums}; albumIndex++ )); do
curl -sL https://source.unsplash.com/random -o "$pic"
done
prevMD5+=("$(md5sum $pic | awk '{print $1}')")
aws s3 cp "$pic" "s3://$rootBucket-original/pics/original/Album $albumNumber/0$picIndex.jpg" >> /dev/null 2>&1
aws s3 cp "$pic" "s3://$originalBucket/pics/original/Album $albumNumber/0$picIndex.jpg" >> /dev/null 2>&1
done
done
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d1da144

Please sign in to comment.