Skip to content

Commit 5a9c3bf

Browse files
committed
Add Build and Publish scripts.
1 parent 3619281 commit 5a9c3bf

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.vscode
3+
export
34

45
# Byte-compiled / optimized / DLL files
56
__pycache__/

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SHELL = /usr/bin/env bash -xe
2+
3+
PWD := $(shell pwd)
4+
5+
build:
6+
@rm -rf export
7+
@mkdir export
8+
@zip -yr export/layer.zip bootstrap bin lib libexec share
9+
10+
publish:
11+
@$(PWD)/publish.sh
12+
13+
.PHONY: \
14+
build
15+
publish

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ Bash behaves in ways unlike other programming languages. As such, there are some
140140

141141
`AWS_LAMBDA_TRACE_ID` - The sampling decision, trace ID, and parent segment ID of AWS XRay
142142

143+
### Building
144+
145+
To build a layer, simply run `make build`. This will create a zip archive of the layer in the `export/` directory.
146+
147+
### Publishing
148+
149+
To publish the layer to the public, simply run `make publish`. This will create a new version of the layer from the `export/layer.zip` file (create from the Build step) and give it a global read permission.
150+
151+
### Adding New Executables
152+
153+
Some executables are able to run by themselves and some require additional dependencies that are present on the server. It's hard to cover here case here, but if the executable run by itself it can easily be added. If it has dependencies, you must explore what those dependencies are and how to add them to the layer as well.
154+
155+
You can either add the executable from an Amazon Linux AMI or from the [lambci/lambda-build:python-36](https://github.com/lambci/docker-lambda) Docker image.
156+
157+
_Disclaimer: I usually don't add in executables from pull requests for security reasons. If you would like to see an executable in this layer make an issue and I'll try to add it._
158+
143159
### Included Executables
144160

145161
- `$ aws`

publish.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash -e
2+
3+
# AWS Regions
4+
REGIONS=(
5+
"us-west-1"
6+
"us-west-2"
7+
"us-east-1"
8+
"us-east-2"
9+
"ap-south-1"
10+
"ap-northeast-1"
11+
"ap-northeast-2"
12+
"ap-southeast-1"
13+
"ap-southeast-2"
14+
"ca-central-1"
15+
"eu-central-1"
16+
"eu-north-1"
17+
"eu-west-1"
18+
"eu-west-2"
19+
"eu-west-3"
20+
"sa-east-1"
21+
)
22+
23+
for region in ${REGIONS[@]}; do
24+
echo "Publishing layer to $region..."
25+
26+
LAYER_ARN=$(aws lambda publish-layer-version --region $region --layer-name bash --description "Bash in AWS Lambda [https://github.com/gkrizek/bash-lambda-layer]" --compatible-runtimes provided --license MIT --zip-file fileb://export/layer.zip | jq -r .LayerVersionArn)
27+
POLICY=$(aws lambda add-layer-version-permission --region $region --layer-name bash --version-number $(echo -n $LAYER_ARN | tail -c 1) --statement-id bash-public --action lambda:GetLayerVersion --principal \*)
28+
29+
echo $LAYER_ARN
30+
echo "$region complete"
31+
echo ""
32+
done
33+
34+
echo "Successfully published to all regions"

0 commit comments

Comments
 (0)