-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
101 lines (95 loc) · 3.28 KB
/
Copy pathserverless.yml
File metadata and controls
101 lines (95 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
service: lambda-crystal-sls
plugins:
- serverless-plugin-scripts
custom:
defaultStage: dev
scripts:
hooks:
# sls deploy / sls package 時に bootstrap を静的ビルドする。
# macOS / Apple Silicon でも Lambda(provided.al2023, arm64) 互換の
# 静的バイナリを得るため、linux/arm64 を明示して Docker でビルドする。
# chmod はコンテナ内(root)で実行する。Linux ランナーでは生成物が
# root 所有になり、コンテナ外の runner ユーザーでは chmod できないため。
#
# glibc で静的リンクしたバイナリは provided.al2023 上で外部 HTTPS 通信に
# 失敗する(OpenSSL の初期化エラー)ため、api.github.com / hooks.slack.com
# へ到達できない。musl(Alpine)ベースで静的リンクすると外部通信が復旧する。
# 併せて静的リンクに必要なライブラリ(OpenSSL / zlib / libevent)を
# apk add --no-cache で明示導入し、ベースイメージ更新時のリンク失敗を防ぐ。
'before:package:createDeploymentArtifacts': |
docker run --rm --platform linux/arm64 -v "$PWD":/work -w /work crystallang/crystal:latest-alpine \
sh -c "apk add --no-cache openssl-libs-static zlib-static libevent-static && crystal build --link-flags -static -o bootstrap src/main.cr && chmod +x bootstrap"
provider:
name: aws
runtime: provided.al2023
architecture: arm64
timeout: 20
region: ap-northeast-1
stage: ${opt:stage, self:custom.defaultStage}
# environment:
# ${file(./env.yml)}
package:
patterns:
- '!./**'
- bootstrap
functions:
# provided ランタイムはパッケージ直下の bootstrap を実行する。
# handler 文字列は _HANDLER として渡され、src/main.cr の
# Serverless::Lambda.handler "..." と一致させることで処理を振り分ける。
hello:
handler: hello
events:
- http:
path: test
method: get
world:
handler: world
events:
- http:
path: test
method: post
# =====================================================================
# Docker(ECR イメージ)版【旧構成・参考用にコメントアウトで残す】
# ---------------------------------------------------------------------
# Dockerfile から ECR イメージをビルドし、image.command で各関数の
# _HANDLER を切り替えていた。zip 版へ移行したため無効化。
# ---------------------------------------------------------------------
# custom:
# defaultAccount: dummy
# defaultDigest: dummy
# defaultStage: dev
#
# provider:
# name: aws
# runtime: provided
# timeout: 20
# region: ap-northeast-1
# ecr:
# images:
# appImage:
# path: ./
# platform: linux/arm64
# stage: ${opt:stage, self:custom.defaultStage}
# # environment:
# # ${file(./env.yml)}
#
# functions:
# hello:
# image:
# name: appImage
# command:
# - hello
# events:
# - http:
# path: test
# method: get
# world:
# image:
# name: appImage
# command:
# - world
# events:
# - http:
# path: test
# method: post
# =====================================================================