Skip to content

Commit 0a65b9b

Browse files
committed
init
1 parent 93c007f commit 0a65b9b

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python/
2+
layer.zip

Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
AWS_PROFILE := default
2+
AWS_REGION := ap-northeast-1
3+
AWS_ACCOUNT_ID := $(shell aws --profile $(AWS_PROFILE) sts get-caller-identity --query Account --output text)
4+
PYTHON_VERSION := 3.11
5+
PIP_COMAND := pip$(PYTHON_VERSION)
6+
ARCHITECTURE := arm64
7+
PLATFORM := linux/$(ARCHITECTURE)
8+
LAYER_NAME := psycopg2-binary-$(PYTHON_VERSION)-$(ARCHITECTURE)
9+
CONTAINER_IMAGE := public.ecr.aws/lambda/python:$(PYTHON_VERSION)
10+
11+
.PHONY: push deploy
12+
13+
build:
14+
docker run --rm \
15+
--platform=$(PLATFORM) \
16+
-v $(PWD):/work \
17+
-w /work \
18+
--entrypoint $(PIP_COMAND) \
19+
$(CONTAINER_IMAGE) \
20+
install -r requirements.txt -t python
21+
find python/ -name '*.pyc' -delete
22+
find python/ -name '__pycache__' -type d -delete
23+
zip -r layer.zip python/
24+
unzip -l layer.zip
25+
26+
deploy: build
27+
aws --profile $(AWS_PROFILE) --region $(AWS_REGION) \
28+
lambda publish-layer-version --layer-name $(subst .,-,$(LAYER_NAME)) \
29+
--description "psycopg2-binary $(PYTHON_VERSION) $(ARCHITECTURE)" \
30+
--zip-file fileb://layer.zip \
31+
--compatible-runtimes python$(PYTHON_VERSION) \
32+
--compatible-architectures $(ARCHITECTURE)
33+
rm -rf python/ layer.zip

README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# lambda-layer-psycopg2-binary
1+
# lambda-layer-psycopg2-binary
2+
3+
install psycopg2-binary
4+
5+
## requirements
6+
7+
- docker (or compatible runtime)
8+
- AWS-CLI
9+
- GNU Make
10+
11+
## Deploy
12+
13+
```
14+
$ AWS_PROFILE=`YOUR_PROFILE` make -e push
15+
16+
#=> "arn:aws:lambda:${REGION}:${YOUR_AWS_ACCOUNT_ID}:layer:psycopg2-binary-3-11-arm64:1"
17+
```
18+
19+
20+
21+
### option (envs)
22+
23+
```
24+
export AWS_PROFILE=...
25+
export AWS_REGION=...
26+
export ARCHITECTURE=[amd64|arm64]
27+
```
28+
29+
check Makefile.
30+

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
psycopg-binary

0 commit comments

Comments
 (0)