apx-aws-lambda 0.3.8__tar.gz → 0.3.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/PKG-INFO +1 -1
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/lambda_.py +49 -0
- apx_aws_lambda-0.3.10/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/Makefile +19 -0
- apx_aws_lambda-0.3.10/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/lambda_handler.rb +70 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda.egg-info/PKG-INFO +1 -1
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/pyproject.toml +1 -1
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/tests/test_targets.py +54 -0
- apx_aws_lambda-0.3.8/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/Makefile +0 -11
- apx_aws_lambda-0.3.8/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/lambda_handler.rb +0 -54
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/LICENSE +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/README.md +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/__init__.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/cli.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/go/Makefile +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/go/cmd/lambda/main.go +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/go/template.yaml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/java/Makefile +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/java/run.sh +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/java/template.yaml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/kotlin/Makefile +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/kotlin/run.sh +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/kotlin/template.yaml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/node/Makefile +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/node/run.sh +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/node/template.yaml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/lambda_handler.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/template.yaml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/tools/lambda_requirements.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/template.yaml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/overlays/index.json +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/plugin.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/proxy.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/shell.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda/tools.py +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda.egg-info/SOURCES.txt +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda.egg-info/requires.txt +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/apx_aws_lambda.egg-info/top_level.txt +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/setup.cfg +0 -0
- {apx_aws_lambda-0.3.8 → apx_aws_lambda-0.3.10}/tests/test_proxy.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-aws-lambda
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.10
|
|
4
4
|
Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -11,6 +11,7 @@ from dataclasses import replace
|
|
|
11
11
|
from action_platform.abc import DeployTarget
|
|
12
12
|
from action_platform.core.context import Context, DeployResult, Diagnosis
|
|
13
13
|
from action_platform.core.exception import ActionPlatformError, DeployError
|
|
14
|
+
from action_platform.logging import logger
|
|
14
15
|
from action_platform.remote.client import Remote
|
|
15
16
|
|
|
16
17
|
from apx_aws_lambda import shell
|
|
@@ -154,11 +155,59 @@ class LambdaTarget(DeployTarget):
|
|
|
154
155
|
env=self.env(ctx),
|
|
155
156
|
)
|
|
156
157
|
|
|
158
|
+
def _status(self, ctx: Context) -> str | None:
|
|
159
|
+
"""The stack's CloudFormation status, or None when there is no stack."""
|
|
160
|
+
try:
|
|
161
|
+
data = shell.aws(
|
|
162
|
+
"cloudformation",
|
|
163
|
+
"describe-stacks",
|
|
164
|
+
"--stack-name",
|
|
165
|
+
self._stack(ctx),
|
|
166
|
+
region=self._region(ctx),
|
|
167
|
+
env=self.env(ctx),
|
|
168
|
+
)
|
|
169
|
+
except DeployError:
|
|
170
|
+
return None
|
|
171
|
+
|
|
172
|
+
rows = data.get("Stacks") or []
|
|
173
|
+
|
|
174
|
+
return rows[0].get("StackStatus") if rows else None
|
|
175
|
+
|
|
176
|
+
def _clear_failed_creation(self, ctx: Context) -> None:
|
|
177
|
+
"""A stack whose first creation failed sits in ROLLBACK_COMPLETE and refuses updates; it never existed, so it is deleted before the deploy creates it again."""
|
|
178
|
+
if self._status(ctx) != "ROLLBACK_COMPLETE":
|
|
179
|
+
return
|
|
180
|
+
|
|
181
|
+
stack = self._stack(ctx)
|
|
182
|
+
logger.info(
|
|
183
|
+
"stack %s is ROLLBACK_COMPLETE: deleting it before the deploy", stack
|
|
184
|
+
)
|
|
185
|
+
region = self._region(ctx)
|
|
186
|
+
env = self.env(ctx)
|
|
187
|
+
shell.aws(
|
|
188
|
+
"cloudformation",
|
|
189
|
+
"delete-stack",
|
|
190
|
+
"--stack-name",
|
|
191
|
+
stack,
|
|
192
|
+
region=region,
|
|
193
|
+
env=env,
|
|
194
|
+
)
|
|
195
|
+
shell.aws(
|
|
196
|
+
"cloudformation",
|
|
197
|
+
"wait",
|
|
198
|
+
"stack-delete-complete",
|
|
199
|
+
"--stack-name",
|
|
200
|
+
stack,
|
|
201
|
+
region=region,
|
|
202
|
+
env=env,
|
|
203
|
+
)
|
|
204
|
+
|
|
157
205
|
def deploy(self, ctx: Context) -> DeployResult:
|
|
158
206
|
sam = shell.require("sam", "pip install aws-sam-cli")
|
|
159
207
|
stage = self._stage(ctx)
|
|
160
208
|
env = self.env(ctx)
|
|
161
209
|
shell.run([*sam, "build"], cwd=ctx.repo_root, env=env)
|
|
210
|
+
self._clear_failed_creation(ctx)
|
|
162
211
|
args = [
|
|
163
212
|
*sam,
|
|
164
213
|
"deploy",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SAM build recipe (BuildMethod: makefile): the app, its gems and the handler.
|
|
2
|
+
# Lambda calls the Rack app directly, so the server gems (puma, rackup — native extensions) stay out:
|
|
3
|
+
# a Gemfile without them is resolved for the package, and the build host needs no compiler.
|
|
4
|
+
# Bundler is driven by environment only — the project's own .bundle/config is never touched.
|
|
5
|
+
|
|
6
|
+
LAMBDA_BUNDLE = BUNDLE_GEMFILE=Gemfile.lambda BUNDLE_PATH=vendor/lambda BUNDLE_WITHOUT=development:test BUNDLE_FROZEN=false
|
|
7
|
+
|
|
8
|
+
build-ApiFunction:
|
|
9
|
+
grep -v -E '^\s*gem "(puma|rackup)"' Gemfile > Gemfile.lambda
|
|
10
|
+
$(LAMBDA_BUNDLE) bundle install --quiet
|
|
11
|
+
cp -r app "$(ARTIFACTS_DIR)/app"
|
|
12
|
+
cp app.rb config.ru lambda_handler.rb "$(ARTIFACTS_DIR)/"
|
|
13
|
+
cp Gemfile.lambda "$(ARTIFACTS_DIR)/Gemfile"
|
|
14
|
+
cp Gemfile.lambda.lock "$(ARTIFACTS_DIR)/Gemfile.lock"
|
|
15
|
+
mkdir -p "$(ARTIFACTS_DIR)/vendor/bundle" "$(ARTIFACTS_DIR)/.bundle"
|
|
16
|
+
cp -r vendor/lambda/. "$(ARTIFACTS_DIR)/vendor/bundle/"
|
|
17
|
+
printf 'BUNDLE_PATH: "vendor/bundle"\nBUNDLE_WITHOUT: "development:test"\n' > "$(ARTIFACTS_DIR)/.bundle/config"
|
|
18
|
+
rm -rf vendor/lambda Gemfile.lambda Gemfile.lambda.lock
|
|
19
|
+
rmdir vendor 2>/dev/null || true
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Lambda entry point: the Rack app from app.rb, called with the request API Gateway
|
|
4
|
+
# (HTTP API, payload v2) delivers. No adapter gem, no server: the event becomes a
|
|
5
|
+
# Rack env, the triplet becomes the response.
|
|
6
|
+
|
|
7
|
+
require "bundler/setup"
|
|
8
|
+
|
|
9
|
+
require "base64"
|
|
10
|
+
require "rack"
|
|
11
|
+
require "stringio"
|
|
12
|
+
|
|
13
|
+
require_relative "app"
|
|
14
|
+
|
|
15
|
+
APP = App.create
|
|
16
|
+
BODY_HEADERS = %w[content-type content-length].freeze
|
|
17
|
+
|
|
18
|
+
def handler(event:, context:)
|
|
19
|
+
status, headers, body = APP.call(rack_env(event, context))
|
|
20
|
+
chunks = body.map(&:to_s)
|
|
21
|
+
body.close if body.respond_to?(:close)
|
|
22
|
+
|
|
23
|
+
{
|
|
24
|
+
"statusCode" => status,
|
|
25
|
+
"headers" => headers.to_h.transform_values(&:to_s),
|
|
26
|
+
"body" => chunks.join,
|
|
27
|
+
"isBase64Encoded" => false
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def rack_env(event, context)
|
|
32
|
+
headers = (event["headers"] || {}).transform_keys { |k| k.to_s.downcase }
|
|
33
|
+
env = base_env(event, headers, context)
|
|
34
|
+
headers.each { |name, value| env[header_key(name)] = value }
|
|
35
|
+
env
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
RACK_STATIC = {
|
|
39
|
+
"SCRIPT_NAME" => "",
|
|
40
|
+
"SERVER_PORT" => "443",
|
|
41
|
+
"SERVER_PROTOCOL" => "HTTP/1.1",
|
|
42
|
+
"rack.version" => Rack::VERSION,
|
|
43
|
+
"rack.url_scheme" => "https",
|
|
44
|
+
"rack.errors" => $stderr,
|
|
45
|
+
"rack.multithread" => false,
|
|
46
|
+
"rack.multiprocess" => false,
|
|
47
|
+
"rack.run_once" => false
|
|
48
|
+
}.freeze
|
|
49
|
+
|
|
50
|
+
def base_env(event, headers, context)
|
|
51
|
+
RACK_STATIC.merge(
|
|
52
|
+
"REQUEST_METHOD" => event.fetch("requestContext").fetch("http")["method"],
|
|
53
|
+
"PATH_INFO" => event["rawPath"] || "/",
|
|
54
|
+
"QUERY_STRING" => event["rawQueryString"].to_s,
|
|
55
|
+
"SERVER_NAME" => headers["host"] || "localhost",
|
|
56
|
+
"rack.input" => StringIO.new(request_body(event)),
|
|
57
|
+
"lambda.event" => event,
|
|
58
|
+
"lambda.context" => context
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def request_body(event)
|
|
63
|
+
body = event["body"].to_s
|
|
64
|
+
event["isBase64Encoded"] ? Base64.decode64(body) : body
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def header_key(name)
|
|
68
|
+
key = name.upcase.tr("-", "_")
|
|
69
|
+
BODY_HEADERS.include?(name) ? key : "HTTP_#{key}"
|
|
70
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-aws-lambda
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.10
|
|
4
4
|
Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -90,6 +90,60 @@ class LambdaTargetTest(unittest.TestCase):
|
|
|
90
90
|
self.assertEqual(result.url, "https://x")
|
|
91
91
|
self.assertEqual(result.version, "1.2.0")
|
|
92
92
|
|
|
93
|
+
def test_a_stack_left_in_rollback_complete_is_deleted_before_the_deploy(self):
|
|
94
|
+
target = LambdaTarget()
|
|
95
|
+
statuses = iter(["ROLLBACK_COMPLETE", "UPDATE_COMPLETE"])
|
|
96
|
+
|
|
97
|
+
def run(args, cwd=None, env=None):
|
|
98
|
+
self.calls.append([Path(args[0]).name, *args[1:]])
|
|
99
|
+
key = " ".join(args[1:3])
|
|
100
|
+
|
|
101
|
+
if key == "cloudformation describe-stacks":
|
|
102
|
+
return json.dumps(
|
|
103
|
+
{
|
|
104
|
+
"Stacks": [
|
|
105
|
+
{
|
|
106
|
+
"StackStatus": next(statuses),
|
|
107
|
+
"Outputs": [
|
|
108
|
+
{"OutputKey": "ApiUrl", "OutputValue": "https://x"}
|
|
109
|
+
],
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return "{}"
|
|
116
|
+
|
|
117
|
+
with mock.patch.multiple(
|
|
118
|
+
shell, run=run, require=lambda tool, hint: [f"/usr/bin/{tool}"]
|
|
119
|
+
):
|
|
120
|
+
result = target.deploy(self.ctx("dev"))
|
|
121
|
+
|
|
122
|
+
names = [c[:3] for c in self.calls]
|
|
123
|
+
self.assertIn(["aws", "cloudformation", "delete-stack"], names)
|
|
124
|
+
self.assertIn(["aws", "cloudformation", "wait"], names)
|
|
125
|
+
self.assertLess(
|
|
126
|
+
names.index(["aws", "cloudformation", "delete-stack"]),
|
|
127
|
+
names.index(["sam", "deploy", "--no-confirm-changeset"]),
|
|
128
|
+
)
|
|
129
|
+
self.assertTrue(result.ok)
|
|
130
|
+
|
|
131
|
+
def test_a_healthy_stack_is_left_alone(self):
|
|
132
|
+
target = LambdaTarget()
|
|
133
|
+
|
|
134
|
+
with self.fake(
|
|
135
|
+
{
|
|
136
|
+
"cloudformation describe-stacks": {
|
|
137
|
+
"Stacks": [{"StackStatus": "UPDATE_COMPLETE", "Outputs": []}]
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
):
|
|
141
|
+
target.deploy(self.ctx("dev"))
|
|
142
|
+
|
|
143
|
+
self.assertNotIn(
|
|
144
|
+
["aws", "cloudformation", "delete-stack"], [c[:3] for c in self.calls]
|
|
145
|
+
)
|
|
146
|
+
|
|
93
147
|
def test_diagnose_reads_the_stack(self):
|
|
94
148
|
with self.fake(
|
|
95
149
|
{
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# SAM build recipe (BuildMethod: makefile): the app, its gems (without the development and test groups) and the handler.
|
|
2
|
-
# Only pure-Ruby gems are loaded on Lambda (rack, sinatra); puma stays in the Gemfile for local runs and is never required there.
|
|
3
|
-
|
|
4
|
-
build-ApiFunction:
|
|
5
|
-
bundle config set --local path vendor/bundle
|
|
6
|
-
bundle config set --local without development:test
|
|
7
|
-
bundle install --quiet
|
|
8
|
-
cp -r app "$(ARTIFACTS_DIR)/app"
|
|
9
|
-
cp app.rb config.ru Gemfile Gemfile.lock lambda_handler.rb "$(ARTIFACTS_DIR)/"
|
|
10
|
-
cp -r vendor "$(ARTIFACTS_DIR)/vendor"
|
|
11
|
-
cp -r .bundle "$(ARTIFACTS_DIR)/.bundle"
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Lambda entry point: the Rack app from app.rb called with the request API Gateway (HTTP API, payload v2) delivers.
|
|
4
|
-
# No adapter gem and no server: the event becomes a Rack env, the triplet becomes the response.
|
|
5
|
-
|
|
6
|
-
require "base64"
|
|
7
|
-
require "rack"
|
|
8
|
-
require "stringio"
|
|
9
|
-
|
|
10
|
-
require_relative "app"
|
|
11
|
-
|
|
12
|
-
APP = App.create
|
|
13
|
-
|
|
14
|
-
def handler(event:, context:)
|
|
15
|
-
http = event.fetch("requestContext").fetch("http")
|
|
16
|
-
body = event["body"].to_s
|
|
17
|
-
body = Base64.decode64(body) if event["isBase64Encoded"]
|
|
18
|
-
headers = (event["headers"] || {}).transform_keys { |k| k.to_s.downcase }
|
|
19
|
-
|
|
20
|
-
env = {
|
|
21
|
-
"REQUEST_METHOD" => http["method"],
|
|
22
|
-
"SCRIPT_NAME" => "",
|
|
23
|
-
"PATH_INFO" => event["rawPath"] || "/",
|
|
24
|
-
"QUERY_STRING" => event["rawQueryString"].to_s,
|
|
25
|
-
"SERVER_NAME" => headers["host"] || "localhost",
|
|
26
|
-
"SERVER_PORT" => "443",
|
|
27
|
-
"SERVER_PROTOCOL" => "HTTP/1.1",
|
|
28
|
-
"rack.version" => Rack::VERSION,
|
|
29
|
-
"rack.url_scheme" => "https",
|
|
30
|
-
"rack.input" => StringIO.new(body),
|
|
31
|
-
"rack.errors" => $stderr,
|
|
32
|
-
"rack.multithread" => false,
|
|
33
|
-
"rack.multiprocess" => false,
|
|
34
|
-
"rack.run_once" => false,
|
|
35
|
-
"lambda.event" => event,
|
|
36
|
-
"lambda.context" => context
|
|
37
|
-
}
|
|
38
|
-
headers.each do |name, value|
|
|
39
|
-
key = name.upcase.tr("-", "_")
|
|
40
|
-
env[%w[content-type content-length].include?(name) ? key : "HTTP_#{key}"] = value
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
status, response_headers, response_body = APP.call(env)
|
|
44
|
-
chunks = []
|
|
45
|
-
response_body.each { |chunk| chunks << chunk }
|
|
46
|
-
response_body.close if response_body.respond_to?(:close)
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
"statusCode" => status,
|
|
50
|
-
"headers" => response_headers.to_h.transform_values(&:to_s),
|
|
51
|
-
"body" => chunks.join,
|
|
52
|
-
"isBase64Encoded" => false
|
|
53
|
-
}
|
|
54
|
-
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|