Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Commit

Permalink
Update deployment scripts for multiple PHP version layers
Browse files Browse the repository at this point in the history
  • Loading branch information
txase committed Feb 5, 2019
1 parent 4a02416 commit 68fd9c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
21 changes: 12 additions & 9 deletions publish.sh
Expand Up @@ -2,18 +2,21 @@

source regions.sh

MD5SUM=$(md5 -q php71.zip)
S3KEY="php71/${MD5SUM}"
PHP_VERSION="${1}"

for region in "${PHP71_REGIONS[@]}"; do
LAYER="php${PHP_VERSION//.}"
MD5SUM=$(md5 -q "${LAYER}.zip")
S3KEY="${LAYER}/${MD5SUM}"

for region in "${PHP_REGIONS[@]}"; do
bucket_name="stackery-layers-${region}"

echo "Publishing Lambda Layer php71 in region ${region}..."
echo "Publishing Lambda Layer ${LAYER} in region ${region}..."
# Must use --cli-input-json so AWS CLI doesn't attempt to fetch license URL
version=$(aws --region $region lambda publish-layer-version --cli-input-json "{\"LayerName\": \"php71\",\"Description\": \"PHP 7.1 Web Server Lambda Runtime\",\"Content\": {\"S3Bucket\": \"${bucket_name}\",\"S3Key\": \"${S3KEY}\"},\"CompatibleRuntimes\": [\"provided\"],\"LicenseInfo\": \"http://www.php.net/license/3_01.txt\"}" --output text --query Version)
echo "Published Lambda Layer php71 in region ${region} version ${version}"
version=$(aws --region $region lambda publish-layer-version --cli-input-json "{\"LayerName\": \"${LAYER}\",\"Description\": \"PHP ${PHP_VERSION} Web Server Lambda Runtime\",\"Content\": {\"S3Bucket\": \"${bucket_name}\",\"S3Key\": \"${S3KEY}\"},\"CompatibleRuntimes\": [\"provided\"],\"LicenseInfo\": \"http://www.php.net/license/3_01.txt\"}" --output text --query Version)
echo "Published Lambda Layer ${LAYER} in region ${region} version ${version}"

echo "Setting public permissions on Lambda Layer php71 version ${version} in region ${region}..."
aws --region $region lambda add-layer-version-permission --layer-name php71 --version-number $version --statement-id=public --action lambda:GetLayerVersion --principal '*' > /dev/null
echo "Public permissions set on Lambda Layer php71 version ${version} in region ${region}"
echo "Setting public permissions on Lambda Layer ${LAYER} version ${version} in region ${region}..."
aws --region $region lambda add-layer-version-permission --layer-name "${LAYER}" --version-number $version --statement-id=public --action lambda:GetLayerVersion --principal '*' > /dev/null
echo "Public permissions set on Lambda Layer ${LAYER} version ${version} in region ${region}"
done
2 changes: 1 addition & 1 deletion regions.sh
@@ -1,4 +1,4 @@
PHP71_REGIONS=(
PHP_REGIONS=(
ap-northeast-1
ap-northeast-2
ap-south-1
Expand Down
16 changes: 9 additions & 7 deletions unpublish.sh
@@ -1,16 +1,18 @@
#!/bin/bash -e

VERSION=$1
PHP_VERSION="${1}"
LAYER_VERSION="${2}"

source regions.sh

MD5SUM=$(md5 -q php71.zip)
S3KEY="php71/${MD5SUM}"
LAYER="php${PHP_VERSION//.}"
MD5SUM=$(md5 -q "${LAYER}.zip")
S3KEY="${LAYER}/${MD5SUM}"

for region in "${PHP71_REGIONS[@]}"; do
for region in "${PHP_REGIONS[@]}"; do
bucket_name="stackery-layers-${region}"

echo "Deleting Lambda Layer php71 version ${VERSION} in region ${region}..."
aws --region $region lambda delete-layer-version --layer-name php71 --version-number $VERSION > /dev/null
echo "Deleted Lambda Layer php71 version ${VERSION} in region ${region}"
echo "Deleting Lambda Layer ${LAYER} version ${VERSION} in region ${region}..."
aws --region $region lambda delete-layer-version --layer-name ${LAYER} --version-number $VERSION > /dev/null
echo "Deleted Lambda Layer ${LAYER} version ${VERSION} in region ${region}"
done
13 changes: 8 additions & 5 deletions upload.sh
Expand Up @@ -2,13 +2,16 @@

source regions.sh

MD5SUM=$(md5 -q php71.zip)
S3KEY="php71/${MD5SUM}"
PHP_VERSION="${1}"

for region in "${PHP71_REGIONS[@]}"; do
LAYER="php${PHP_VERSION//.}"
MD5SUM=$(md5 -q "${LAYER}.zip")
S3KEY="${LAYER}/${MD5SUM}"

for region in "${PHP_REGIONS[@]}"; do
bucket_name="stackery-layers-${region}"

echo "Uploading php71.zip to s3://${bucket_name}/${S3KEY}"
echo "Uploading ${LAYER}.zip to s3://${bucket_name}/${S3KEY}"

aws --region $region s3 cp php71.zip "s3://${bucket_name}/${S3KEY}"
aws --region $region s3 cp ${LAYER}.zip "s3://${bucket_name}/${S3KEY}"
done

0 comments on commit 68fd9c5

Please sign in to comment.