aws_lambda_ric 1.0.0 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf1124bbf50d67d952fa22fcd35345899f5f8051e4c3d2be9ba87f0cc701cabb
4
- data.tar.gz: e32410af6693b00bb5ed60e6f7c1ff99d7dec53d4484982c18c338920ed401ce
3
+ metadata.gz: e7531514e0f2ab9ba840cdcd973a36cadb45e9887db24a7fa0337e6eaca16e8a
4
+ data.tar.gz: b1be16c96fdc08b4651e99a4eb20f17ca3af69dee48476e58b075b910863a72d
5
5
  SHA512:
6
- metadata.gz: '005869f4ece8cdd2a5c93e771d377c8d4107121f0916259ecdf62bd57d5e4bc695dabad4f7695d70155c22bce0d5f13ec0be9db396f7dad86c8d364595d4d81c'
7
- data.tar.gz: fa08b30481f6ead00ab458515b8f4eef8ce8c4190432f879408329031383bb190cde4dcc7bd8691709d1220c98d80ff98d7561d984822b075f040ee2fb74982d
6
+ metadata.gz: 7a9d932188a665f2865a71c9e7d06a6864fd7728925589e587c3ef71926c20ae0345cb9b7879c7457f586f7956df3ec41260038464ef34d50af6a785c81cfd71
7
+ data.tar.gz: 2b00da39020716fda73d50954e74ec76013a2aa0548c363411d743c03e01b888ff59a123921cf8915bef617cae0ebde7a35743588a589ca56edb5649fb88a956
data/LICENSE CHANGED
@@ -1,229 +1,175 @@
1
- Apache License
2
1
 
3
- Version 2.0, January 2004
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
4
5
 
5
- http://www.apache.org/licenses/ TERMS
6
- AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
7
 
8
8
  1. Definitions.
9
9
 
10
-
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
11
12
 
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
12
15
 
13
- "License" shall mean the terms and conditions for use, reproduction, and
14
- distribution as defined by Sections 1 through 9 of this document.
15
-
16
-
17
-
18
-
19
- "Licensor" shall mean the copyright owner or entity authorized by the copyright
20
- owner that is granting the License.
21
-
22
-
23
-
24
- "Legal Entity" shall mean the
25
- union of the acting entity and all other entities that control, are controlled
26
- by, or are under common control with that entity. For the purposes of this
27
- definition, "control" means (i) the power, direct or indirect, to cause the
28
- direction or management of such entity, whether by contract or otherwise, or (ii)
29
- ownership of fifty percent (50%) or more of the outstanding shares, or (iii)
30
- beneficial ownership of such entity.
31
-
32
-
33
-
34
- "You" (or "Your") shall mean
35
- an individual or Legal Entity exercising permissions granted by this License.
36
-
37
-
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
23
 
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
39
26
 
40
27
  "Source" form shall mean the preferred form for making modifications,
41
- including but not limited to software source code, documentation source, and
42
- configuration files.
43
-
44
-
45
-
46
- "Object" form shall mean any form resulting
47
- from mechanical transformation or translation of a Source form, including but not
48
- limited to compiled object code, generated documentation, and conversions to
49
- other media types.
50
-
51
-
52
-
53
- "Work" shall mean the work of authorship,
54
- whether in Source or Object form, made available under the License, as indicated
55
- by a copyright notice that is included in or attached to the work (an example is
56
- provided in the Appendix below).
57
-
58
-
59
-
60
- "Derivative Works" shall mean any
61
- work, whether in Source or Object form, that is based on (or derived from) the
62
- Work and for which the editorial revisions, annotations, elaborations, or other
63
- modifications represent, as a whole, an original work of authorship. For the
64
- purposes of this License, Derivative Works shall not include works that remain
65
- separable from, or merely link (or bind by name) to the interfaces of, the Work
66
- and Derivative Works thereof.
67
-
68
-
69
-
70
- "Contribution" shall mean any work
71
- of authorship, including the original version of the Work and any modifications
72
- or additions to that Work or Derivative Works thereof, that is intentionally
73
- submitted to Licensor for inclusion in the Work by the copyright owner or by an
74
- individual or Legal Entity authorized to submit on behalf of the copyright owner.
75
- For the purposes of this definition, "submitted" means any form of electronic,
76
- verbal, or written communication sent to the Licensor or its representatives,
77
- including but not limited to communication on electronic mailing lists, source
78
- code control systems, and issue tracking systems that are managed by, or on
79
- behalf of, the Licensor for the purpose of discussing and improving the Work, but
80
- excluding communication that is conspicuously marked or otherwise designated in
81
- writing by the copyright owner as "Not a Contribution."
82
-
83
-
84
-
85
-
86
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of
87
- whom a Contribution has been received by Licensor and subsequently incorporated
88
- within the Work.
89
-
90
- 2. Grant of Copyright License. Subject to the terms and
91
- conditions of this License, each Contributor hereby grants to You a perpetual,
92
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license
93
- to reproduce, prepare Derivative Works of, publicly display, publicly perform,
94
- sublicense, and distribute the Work and such Derivative Works in Source or Object
95
- form.
96
-
97
- 3. Grant of Patent License. Subject to the terms and conditions of this
98
- License, each Contributor hereby grants to You a perpetual, worldwide,
99
- non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
100
- section) patent license to make, have made, use, offer to sell, sell, import, and
101
- otherwise transfer the Work, where such license applies only to those patent
102
- claims licensable by such Contributor that are necessarily infringed by their
103
- Contribution(s) alone or by combination of their Contribution(s) with the Work to
104
- which such Contribution(s) was submitted. If You institute patent litigation
105
- against any entity (including a cross-claim or counterclaim in a lawsuit)
106
- alleging that the Work or a Contribution incorporated within the Work constitutes
107
- direct or contributory patent infringement, then any patent licenses granted to
108
- You under this License for that Work shall terminate as of the date such
109
- litigation is filed.
110
-
111
- 4. Redistribution. You may reproduce and distribute
112
- copies of the Work or Derivative Works thereof in any medium, with or without
113
- modifications, and in Source or Object form, provided that You meet the following
114
- conditions:
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
115
94
 
116
95
  (a) You must give any other recipients of the Work or
117
- Derivative Works a copy of this License; and
118
-
119
- (b) You must cause any
120
- modified files to carry prominent notices stating that You changed the files;
121
- and
122
-
123
- (c) You must retain, in the Source form of any Derivative Works that
124
- You distribute, all copyright, patent, trademark, and attribution notices from
125
- the Source form of the Work, excluding those notices that do not pertain to any
126
- part of the Derivative Works; and
127
-
128
- (d) If the Work includes a "NOTICE" text
129
- file as part of its distribution, then any Derivative Works that You distribute
130
- must include a readable copy of the attribution notices contained within such
131
- NOTICE file, excluding those notices that do not pertain to any part of the
132
- Derivative Works, in at least one of the following places: within a NOTICE text
133
- file distributed as part of the Derivative Works; within the Source form or
134
- documentation, if provided along with the Derivative Works; or, within a display
135
- generated by the Derivative Works, if and wherever such third-party notices
136
- normally appear. The contents of the NOTICE file are for informational purposes
137
- only and do not modify the License. You may add Your own attribution notices
138
- within Derivative Works that You distribute, alongside or as an addendum to the
139
- NOTICE text from the Work, provided that such additional attribution notices
140
- cannot be construed as modifying the License.
141
-
142
- You may add Your own
143
- copyright statement to Your modifications and may provide additional or different
144
- license terms and conditions for use, reproduction, or distribution of Your
145
- modifications, or for any such Derivative Works as a whole, provided Your use,
146
- reproduction, and distribution of the Work otherwise complies with the conditions
147
- stated in this License.
148
-
149
- 5. Submission of Contributions. Unless You explicitly
150
- state otherwise, any Contribution intentionally submitted for inclusion in the
151
- Work by You to the Licensor shall be under the terms and conditions of this
152
- License, without any additional terms or conditions. Notwithstanding the above,
153
- nothing herein shall supersede or modify the terms of any separate license
154
- agreement you may have executed with Licensor regarding such Contributions.
155
-
156
-
157
- 6. Trademarks. This License does not grant permission to use the trade names,
158
- trademarks, service marks, or product names of the Licensor, except as required
159
- for reasonable and customary use in describing the origin of the Work and
160
- reproducing the content of the NOTICE file.
161
-
162
- 7. Disclaimer of Warranty. Unless
163
- required by applicable law or agreed to in writing, Licensor provides the Work
164
- (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT
165
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including,
166
- without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
167
- MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible
168
- for determining the appropriateness of using or redistributing the Work and
169
- assume any risks associated with Your exercise of permissions under this
170
- License.
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
171
153
 
172
154
  8. Limitation of Liability. In no event and under no legal theory,
173
- whether in tort (including negligence), contract, or otherwise, unless required
174
- by applicable law (such as deliberate and grossly negligent acts) or agreed to in
175
- writing, shall any Contributor be liable to You for damages, including any
176
- direct, indirect, special, incidental, or consequential damages of any character
177
- arising as a result of this License or out of the use or inability to use the
178
- Work (including but not limited to damages for loss of goodwill, work stoppage,
179
- computer failure or malfunction, or any and all other commercial damages or
180
- losses), even if such Contributor has been advised of the possibility of such
181
- damages.
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
182
165
 
183
166
  9. Accepting Warranty or Additional Liability. While redistributing
184
- the Work or Derivative Works thereof, You may choose to offer, and charge a fee
185
- for, acceptance of support, warranty, indemnity, or other liability obligations
186
- and/or rights consistent with this License. However, in accepting such
187
- obligations, You may act only on Your own behalf and on Your sole responsibility,
188
- not on behalf of any other Contributor, and only if You agree to indemnify,
189
- defend, and hold each Contributor harmless for any liability incurred by, or
190
- claims asserted against, such Contributor by reason of your accepting any such
191
- warranty or additional liability. END OF TERMS AND CONDITIONS
192
-
193
- APPENDIX: How to
194
- apply the Apache License to your work.
195
-
196
- To apply the Apache License to your work,
197
- attach the following boilerplate notice, with the fields enclosed by brackets
198
- "[]" replaced with your own identifying information. (Don't include the
199
- brackets!) The text should be enclosed in the appropriate comment syntax for the
200
- file format. We also recommend that a file or class name and description of
201
- purpose be included on the same "printed page" as the copyright notice for easier
202
- identification within third-party archives.
203
-
204
- Copyright [yyyy] Edgar
205
- Hernandez
206
-
207
- Licensed under the Apache License, Version 2.0 (the "License");
208
-
209
- you
210
- may not use this file except in compliance with the License.
211
-
212
- You may obtain a
213
- copy of the License at
214
-
215
- http://www.apache.org/licenses/LICENSE-2.0
216
-
217
- Unless
218
- required by applicable law or agreed to in writing, software
219
-
220
- distributed under
221
- the License is distributed on an "AS IS" BASIS,
222
-
223
- WITHOUT WARRANTIES OR CONDITIONS
224
- OF ANY KIND, either express or implied.
225
-
226
- See the License for the specific
227
- language governing permissions and
228
-
229
- limitations under the License.
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
data/README.md CHANGED
@@ -19,7 +19,6 @@ First step is to choose the base image to be used. The supported Linux OS distri
19
19
 
20
20
  - Amazon Linux 2
21
21
  - Alpine
22
- - CentOS
23
22
  - Debian
24
23
  - Ubuntu
25
24
 
@@ -39,12 +38,10 @@ Or install it manually as:
39
38
 
40
39
 
41
40
  Next step would be to copy your Lambda function code into the image's working directory.
42
- ```Docker
43
- # Create function directory
41
+ ```dockerfile
42
+ # Copy function code
44
43
  RUN mkdir -p ${FUNCTION_DIR}
45
-
46
- # Copy handler function
47
- COPY app.rb ${FUNCTION_DIR}/app.rb
44
+ COPY app.rb ${FUNCTION_DIR}
48
45
 
49
46
  WORKDIR ${FUNCTION_DIR}
50
47
  ```
@@ -52,7 +49,7 @@ WORKDIR ${FUNCTION_DIR}
52
49
  The next step would be to set the `ENTRYPOINT` property of the Docker image to invoke the Runtime Interface Client and then set the `CMD` argument to specify the desired handler.
53
50
 
54
51
  Example Dockerfile:
55
- ```Docker
52
+ ```dockerfile
56
53
  FROM amazonlinux:latest
57
54
 
58
55
  # Define custom function directory
@@ -61,28 +58,28 @@ ARG FUNCTION_DIR="/function"
61
58
  # Install ruby
62
59
  RUN amazon-linux-extras install -y ruby2.6
63
60
 
61
+ # Install bundler
62
+ RUN gem install bundler
63
+
64
64
  # Install the Runtime Interface Client
65
65
  RUN gem install aws_lambda_ric
66
66
 
67
- # Create function directory
67
+ # Copy function code
68
68
  RUN mkdir -p ${FUNCTION_DIR}
69
-
70
- # Copy handler function
71
- COPY app.rb ${FUNCTION_DIR}/app.rb
69
+ COPY app.rb ${FUNCTION_DIR}
72
70
 
73
71
  WORKDIR ${FUNCTION_DIR}
74
72
 
75
- ENTRYPOINT ["aws_lambda_ric"]
73
+ ENTRYPOINT ["/usr/local/bin/aws_lambda_ric"]
76
74
  CMD ["app.App::Handler.process"]
77
75
  ```
78
76
 
79
77
  Example Ruby handler `app.rb`:
80
- ```rb
78
+ ```ruby
81
79
  module App
82
80
  class Handler
83
81
  def self.process(event:, context:)
84
- message = "Hello World!"
85
- { statusCode: 200, body: { 'message': message } }
82
+ "Hello World!"
86
83
  end
87
84
  end
88
85
  end
@@ -90,8 +87,70 @@ end
90
87
 
91
88
  ### Local Testing
92
89
 
93
- For testing locally you will need to set up a local Runtime Interface Emulator against which the Runtime Interface Client will make API calls. You will need to post data to the endpoint it creates in order to invoke your function. For more information check out the [Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator).
90
+ To make it easy to locally test Lambda functions packaged as container images we open-sourced a lightweight web-server, Lambda Runtime Interface Emulator (RIE), which allows your function packaged as a container image to accept HTTP requests. You can install the [AWS Lambda Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) on your local machine to test your function. Then when you run the image function, you set the entrypoint to be the emulator.
91
+
92
+ *To install the emulator and test your Lambda function*
93
+
94
+ 1) From your project directory, run the following command to download the RIE from GitHub and install it on your local machine.
95
+
96
+ ```shell script
97
+ mkdir -p ~/.aws-lambda-rie && \
98
+ curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \
99
+ chmod +x ~/.aws-lambda-rie/aws-lambda-rie
100
+ ```
101
+ 2) Run your Lambda image function using the docker run command.
102
+
103
+ ```shell script
104
+ docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \
105
+ --entrypoint /aws-lambda/aws-lambda-rie \
106
+ myfunction:latest \
107
+ /usr/local/bin/aws_lambda_ric app.App::Handler.process
108
+ ```
109
+
110
+ This runs the image as a container and starts up an endpoint locally at `http://localhost:9000/2015-03-31/functions/function/invocations`.
111
+
112
+ 3) Post an event to the following endpoint using a curl command:
113
+
114
+ ```shell script
115
+ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
116
+ ```
117
+
118
+ This command invokes the function running in the container image and returns a response.
119
+
120
+ *Alternately, you can also include RIE as a part of your base image. See the AWS documentation on how to [Build RIE into your base image](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-alternative).*
121
+
122
+ ## Development
123
+
124
+ ### Building the package
125
+ Clone this repository and run:
126
+
127
+ ```shell script
128
+ make init
129
+ make build
130
+ ```
94
131
 
132
+ ### Running tests
133
+
134
+ Make sure the project is built:
135
+ ```shell script
136
+ make init build
137
+ ```
138
+ Then,
139
+ * to run unit tests: `make test-unit`
140
+ * to run integration tests: `make test-integ`
141
+ * to run smoke tests: `make test-smoke`
142
+
143
+ ### Troubleshooting
144
+ While running integration tests, you might encounter the Docker Hub rate limit error with the following body:
145
+ ```
146
+ You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limits
147
+ ```
148
+ To fix the above issue, consider authenticating to a Docker Hub account by setting the Docker Hub credentials as below CodeBuild environment variables.
149
+ ```shell script
150
+ DOCKERHUB_USERNAME=<dockerhub username>
151
+ DOCKERHUB_PASSWORD=<dockerhub password>
152
+ ```
153
+ Recommended way is to set the Docker Hub credentials in CodeBuild job by retrieving them from AWS Secrets Manager.
95
154
 
96
155
  ## Security
97
156
 
@@ -1,5 +1,3 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
3
  lib = File.expand_path('lib', __dir__)
@@ -7,31 +5,35 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
5
  require './lib/aws_lambda_ric/version'
8
6
 
9
7
  Gem::Specification.new do |spec|
10
- spec.name = 'aws_lambda_ric'
11
- spec.version = AwsLambdaRuntimeInterfaceClient::VERSION
12
- spec.authors = ['AWS Lambda']
8
+ spec.name = 'aws_lambda_ric'
9
+ spec.version = AwsLambdaRIC::VERSION
10
+ spec.authors = ['AWS Lambda']
11
+
12
+ spec.summary = 'AWS Lambda Runtime Interface Client for Ruby'
13
+ spec.description = 'The AWS Lambda Ruby Runtime Interface Client implements the Lambda programming model for Ruby.'
14
+ spec.homepage = 'https://github.com/aws/aws-lambda-ruby-runtime-interface-client'
13
15
 
14
- spec.summary = 'AWS Lambda Runtime Interface Client for Ruby'
15
- spec.description = 'The AWS Lambda Ruby Runtime Interface Client implements the Lambda programming model for Ruby.'
16
- spec.homepage = 'https://github.com/aws/aws-lambda-ruby-runtime-interface-client'
16
+ spec.license = 'Apache-2.0'
17
+ spec.required_ruby_version = '>= 3.0'
17
18
 
18
19
  # Specify which files should be added to the gem when it is released.
19
- spec.files = %w[
20
+ spec.files = %w[
20
21
  LICENSE
21
22
  README.md
22
23
  Gemfile
23
24
  NOTICE
24
- Gemfile.lock
25
25
  aws_lambda_ric.gemspec
26
26
  bin/aws_lambda_ric
27
27
  ] + Dir['lib/**/*']
28
28
 
29
- spec.bindir = 'bin'
29
+ spec.bindir = 'bin'
30
30
  # all application-style files are expected to be found in bindir
31
- spec.executables = 'aws_lambda_ric'
32
- spec.require_paths = ['lib']
31
+ spec.executables = 'aws_lambda_ric'
32
+ spec.require_paths = ['lib']
33
33
 
34
- spec.add_development_dependency 'bundler', '>= 2.0'
34
+ spec.add_development_dependency 'bundler', '~> 2.0'
35
35
  spec.add_development_dependency 'minitest', '~> 5.0'
36
- spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rake', '~> 13.0'
37
+ spec.add_development_dependency 'activesupport', '~> 6.0.1'
38
+ spec.add_development_dependency 'test-unit', '~> 3.5.5'
37
39
  end
data/bin/aws_lambda_ric CHANGED
@@ -1,10 +1,9 @@
1
1
  #! /usr/bin/env ruby
2
-
3
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
-
5
2
  # frozen_string_literal: true
6
3
 
7
4
  require 'bundler/setup'
8
- require_relative '../lib/aws_lambda_ric/bootstrap'
5
+ require_relative '../lib/aws_lambda_ric'
6
+
7
+ lambda_ric = AwsLambdaRIC::Bootstrap.new
9
8
 
10
- Bootstrap.start
9
+ lambda_ric.start
@@ -1,7 +1,7 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
3
+ require 'stringio'
4
+
5
5
  module AwsLambda
6
6
  class Marshaller
7
7
  class << self
@@ -1,5 +1,3 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
3
  class LambdaContext
@@ -17,8 +15,8 @@ class LambdaContext
17
15
  @function_name = ENV['AWS_LAMBDA_FUNCTION_NAME']
18
16
  @memory_limit_in_mb = ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE']
19
17
  @function_version = ENV['AWS_LAMBDA_FUNCTION_VERSION']
20
- @identity = JSON.parse(request['Lambda-Runtime-Cognito-Identity']) if request['Lambda-Runtime-Cognito-Identity']
21
- @client_context = JSON.parse(request['Lambda-Runtime-Client-Context']) if request['Lambda-Runtime-Client-Context']
18
+ @identity = JSON.parse(request['Lambda-Runtime-Cognito-Identity']) unless request['Lambda-Runtime-Cognito-Identity'].to_s.empty?
19
+ @client_context = JSON.parse(request['Lambda-Runtime-Client-Context']) unless request['Lambda-Runtime-Client-Context'].to_s.empty?
22
20
  end
23
21
 
24
22
  def get_remaining_time_in_millis
@@ -1,6 +1,5 @@
1
- # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
2
+
4
3
  module LambdaErrors
5
4
 
6
5
  class LambdaErrors::InvocationError < StandardError;
@@ -25,9 +24,9 @@ module LambdaErrors
25
24
 
26
25
  def to_lambda_response
27
26
  {
28
- :errorMessage => @error_message,
29
- :errorType => @error_type,
30
- :stackTrace => @stack_trace
27
+ :errorMessage => @error_message,
28
+ :errorType => @error_type,
29
+ :stackTrace => @stack_trace
31
30
  }
32
31
  end
33
32
 
@@ -39,7 +38,7 @@ module LambdaErrors
39
38
  if stacktrace
40
39
  stacktrace.first(100).each do |line|
41
40
  if safe_trace
42
- if line.to_s.match(%r{^lib})
41
+ if line.to_s.match(%r{^/var/runtime/lib})
43
42
  safe_trace = false
44
43
  else
45
44
  ret << line
@@ -1,4 +1,4 @@
1
- # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'aws_lambda_marshaller'
4
4
 
@@ -19,8 +19,8 @@ class LambdaHandler
19
19
 
20
20
  def call_handler(request:, context:)
21
21
  opts = {
22
- event: request,
23
- context: context
22
+ event: request,
23
+ context: context
24
24
  }
25
25
  if @handler_class
26
26
  response = Kernel.const_get(@handler_class).send(@handler_method_name, **opts)
@@ -1,11 +1,9 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
3
  require 'logger'
6
4
 
7
- class LambdaLogFormatter < Logger::Formatter
8
- FORMAT = '%<sev>s, [%<datetime>s#%<process>d] %<severity>5s %<request_id>s -- %<progname>s: %<msg>s'
5
+ class LogFormatter < Logger::Formatter
6
+ FORMAT = '%<sev>s, [%<datetime>s #%<process>d] %<severity>5s %<request_id>s -- %<progname>s: %<msg>s'
9
7
 
10
8
  def call(severity, time, progname, msg)
11
9
  (FORMAT % {sev: severity[0..0], datetime: format_datetime(time), process: $$, severity: severity,
@@ -1,4 +1,4 @@
1
- # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1
+ # frozen_string_literal: true
2
2
 
3
3
  class LambdaLogger
4
4
  class << self
@@ -1,37 +1,36 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
3
  require 'net/http'
6
4
  require 'json'
7
5
  require_relative 'lambda_errors'
8
6
 
9
- class LambdaServer
7
+ class RapidClient
10
8
  LAMBDA_DEFAULT_SERVER_ADDRESS = '127.0.0.1:9001'
11
9
  LAMBDA_RUNTIME_API_VERSION = '2018-06-01'
12
10
 
13
- MAX_HEADER_SIZE = 1024 * 1024
14
- LONG_TIMEOUT = 1_000_000
11
+ MAX_HEADER_SIZE_BYTES = 1024 * 1024
12
+ LONG_TIMEOUT_MS = 1_000_000
15
13
 
16
- def initialize(server_address)
14
+ def initialize(server_address, user_agent)
17
15
  server_address ||= LAMBDA_DEFAULT_SERVER_ADDRESS
18
- @server_address = 'http://' + server_address + '/' + LAMBDA_RUNTIME_API_VERSION
16
+ @server_address = "http://#{server_address}/#{LAMBDA_RUNTIME_API_VERSION}"
17
+ @user_agent = user_agent
19
18
  end
20
19
 
21
20
  def next_invocation
22
21
  next_invocation_uri = URI(@server_address + '/runtime/invocation/next')
23
22
  begin
24
23
  http = Net::HTTP.new(next_invocation_uri.host, next_invocation_uri.port)
25
- http.read_timeout = LONG_TIMEOUT
24
+ http.read_timeout = LONG_TIMEOUT_MS
26
25
  resp = http.start do |connection|
27
- connection.get(next_invocation_uri.path)
26
+ connection.get(next_invocation_uri.path, { 'User-Agent' => @user_agent })
28
27
  end
29
28
  if resp.is_a?(Net::HTTPSuccess)
30
29
  request_id = resp['Lambda-Runtime-Aws-Request-Id']
31
30
  [request_id, resp]
32
31
  else
33
32
  raise LambdaErrors::InvocationError.new(
34
- "Received #{resp.code} when waiting for next invocation."
33
+ "Received #{resp.code} when waiting for next invocation."
35
34
  )
36
35
  end
37
36
  rescue LambdaErrors::InvocationError => e
@@ -49,9 +48,9 @@ class LambdaServer
49
48
  response_object = response_object.read
50
49
  end
51
50
  Net::HTTP.post(
52
- response_uri,
53
- response_object,
54
- { 'Content-Type' => content_type }
51
+ response_uri,
52
+ response_object,
53
+ { 'Content-Type' => content_type, 'User-Agent' => @user_agent }
55
54
  )
56
55
  rescue StandardError => e
57
56
  raise LambdaErrors::LambdaRuntimeError.new(e)
@@ -61,12 +60,12 @@ class LambdaServer
61
60
  def send_error_response(request_id:, error_object:, error:, xray_cause:)
62
61
  response_uri = URI(@server_address + "/runtime/invocation/#{request_id}/error")
63
62
  begin
64
- headers = { 'Lambda-Runtime-Function-Error-Type' => error.runtime_error_type }
65
- headers['Lambda-Runtime-Function-XRay-Error-Cause'] = xray_cause if xray_cause.bytesize < MAX_HEADER_SIZE
63
+ headers = { 'Lambda-Runtime-Function-Error-Type' => error.runtime_error_type, 'User-Agent' => @user_agent }
64
+ headers['Lambda-Runtime-Function-XRay-Error-Cause'] = xray_cause if xray_cause.bytesize < MAX_HEADER_SIZE_BYTES
66
65
  Net::HTTP.post(
67
- response_uri,
68
- error_object.to_json,
69
- headers
66
+ response_uri,
67
+ error_object.to_json,
68
+ headers
70
69
  )
71
70
  rescue StandardError => e
72
71
  raise LambdaErrors::LambdaRuntimeError.new(e)
@@ -77,9 +76,9 @@ class LambdaServer
77
76
  uri = URI("#{@server_address}/runtime/init/error")
78
77
  begin
79
78
  Net::HTTP.post(
80
- uri,
81
- error_object.to_json,
82
- { 'Lambda-Runtime-Function-Error-Type' => error.runtime_error_type }
79
+ uri,
80
+ error_object.to_json,
81
+ { 'Lambda-Runtime-Function-Error-Type' => error.runtime_error_type, 'User-Agent' => @user_agent }
83
82
  )
84
83
  rescue StandardError => e
85
84
  raise LambdaErrors::LambdaRuntimeInitError.new(e)
@@ -0,0 +1,22 @@
1
+ # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+
3
+ module LoggerPatch
4
+ def initialize(logdev, shift_age = 0, shift_size = 1048576, level: 'debug',
5
+ progname: nil, formatter: nil, datetime_format: nil,
6
+ binmode: false, shift_period_suffix: '%Y%m%d')
7
+ # use unpatched constructor if logdev is a filename or an IO Object other than $stdout or $stderr
8
+ if logdev && logdev != $stdout && logdev != $stderr
9
+ super(logdev, shift_age, shift_size, level: level, progname: progname,
10
+ formatter: formatter, datetime_format: datetime_format,
11
+ binmode: binmode, shift_period_suffix: shift_period_suffix)
12
+ else
13
+ self.level = level
14
+ self.progname = progname
15
+ @default_formatter = LogFormatter.new
16
+ self.datetime_format = datetime_format
17
+ self.formatter = formatter
18
+ @logdev = AwsLambdaRIC::TelemetryLogger.telemetry_log_sink
19
+ @level_override = {}
20
+ end
21
+ end
22
+ end
@@ -1,35 +1,38 @@
1
- # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
3
  require 'logger'
4
+ require 'time'
6
5
 
7
6
  class TelemetryLogSink < Logger::LogDevice
8
7
 
9
8
  # TelemetryLogSink implements the logging contract between runtimes and the platform. It implements a simple
10
9
  # framing protocol so message boundaries can be determined. Each frame can be visualized as follows:
11
10
  #
12
- # +----------------------+------------------------+-----------------------+
13
- # | Frame Type - 4 bytes | Length (len) - 4 bytes | Message - \'len\' bytes |
14
- # +----------------------+------------------------+-----------------------+
11
+ # +----------------------+------------------------+---------------------+-------------------------+
12
+ # | Frame Type - 4 bytes | Length (len) - 4 bytes | Timestamp - 8 bytes | Message - \'len\' bytes |
13
+ # +----------------------+------------------------+---------------------+-------------------------+
15
14
  #
16
- # The first 4 bytes indicate the type of the frame - log frames have a type defined as the hex value 0xa55a0001. The
17
- # second 4 bytes should indicate the message\'s length. The next \'len\' bytes contain the message. The byte order is
18
- # big-endian.
15
+ # The first 4 bytes indicate the type of the frame - log frames have a type defined as the hex value 0xa55a0003. The
16
+ # second 4 bytes should indicate the message\'s length. Next, the timestamp in microsecond precision, and finally
17
+ # \'len\' bytes contain the message. The byte order is big-endian.
19
18
 
20
19
  def initialize(file:)
21
20
  @file = file
22
21
  end
23
22
 
24
- FRAME_BYTES = [0xa55a0001].pack('L>')
23
+ FRAME_BYTES = [0xa55a0003].pack('L>')
25
24
 
26
25
  def write(msg)
26
+ @semaphore ||= Mutex.new
27
27
  if @file.nil? || @file.closed?
28
28
  $stdout.write(msg)
29
29
  else
30
- @file.write(FRAME_BYTES)
31
- @file.write([msg.bytesize].pack('L>'))
32
- @file.write(msg)
30
+ @semaphore.synchronize do
31
+ @file.write(FRAME_BYTES)
32
+ @file.write([msg.bytesize].pack('L>'))
33
+ @file.write([(Time.new.to_f*1000000).to_i].pack('Q>'))
34
+ @file.write(msg)
35
+ end
33
36
  end
34
37
  end
35
38
 
@@ -1,7 +1,5 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
- module AwsLambdaRuntimeInterfaceClient
6
- VERSION = '1.0.0'
3
+ module AwsLambdaRIC
4
+ VERSION = '3.0.0'
7
5
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'lambda_errors'
4
4
 
@@ -15,8 +15,8 @@ class XRayCause
15
15
 
16
16
  def as_json
17
17
  @as_json ||= begin
18
- JSON.dump(@cause)
19
- end
18
+ JSON.dump(@cause)
19
+ end
20
20
  end
21
21
 
22
22
  private
@@ -39,4 +39,4 @@ class XRayCause
39
39
  end
40
40
  [exception]
41
41
  end
42
- end
42
+ end
@@ -1,5 +1,3 @@
1
- # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
-
3
1
  # frozen_string_literal: true
4
2
 
5
3
  require_relative 'aws_lambda_ric/lambda_errors'
@@ -8,6 +6,7 @@ require_relative 'aws_lambda_ric/lambda_handler'
8
6
  require_relative 'aws_lambda_ric/lambda_context'
9
7
  require_relative 'aws_lambda_ric/lambda_logger'
10
8
  require_relative 'aws_lambda_ric/lambda_log_formatter'
9
+ require_relative 'aws_lambda_ric/logger_patch'
11
10
  require_relative 'aws_lambda_ric/telemetry_log_sink'
12
11
  require_relative 'aws_lambda_ric/aws_lambda_marshaller'
13
12
  require_relative 'aws_lambda_ric/xray_cause'
@@ -16,17 +15,24 @@ require 'logger'
16
15
 
17
16
  $stdout.sync = true # Ensures that logs are flushed promptly.
18
17
 
19
- module AwsLambdaRuntimeInterfaceClient
18
+ module AwsLambdaRIC
20
19
 
21
20
  class Error < StandardError; end
22
21
 
22
+ def self.get_user_agent
23
+ ruby_version = RUBY_VERSION.to_s
24
+ version = AwsLambdaRIC::VERSION
25
+
26
+ "aws-lambda-ruby/#{ruby_version}-#{version}"
27
+ end
28
+
23
29
  # Loads the user code and runs it upon invocation
24
30
  class LambdaRunner
25
31
 
26
32
  ENV_VAR_RUNTIME_API = 'AWS_LAMBDA_RUNTIME_API'
27
33
 
28
- def initialize(runtime_server_addr)
29
- @lambda_server = LambdaServer.new(runtime_server_addr)
34
+ def initialize(runtime_server_addr, user_agent)
35
+ @lambda_server = RapidClient.new(runtime_server_addr, user_agent)
30
36
  @runtime_loop_active = true # if false, we will exit the program
31
37
  @exit_code = 0
32
38
  end
@@ -44,7 +50,7 @@ module AwsLambdaRuntimeInterfaceClient
44
50
  @exit_code = -4
45
51
  send_init_error_to_server(e)
46
52
  ensure
47
- TelemetryLoggingHelper.close
53
+ TelemetryLogger.close
48
54
  end
49
55
 
50
56
  exit(@exit_code)
@@ -105,7 +111,7 @@ module AwsLambdaRuntimeInterfaceClient
105
111
  @lambda_server.send_init_error(error_object: ex.to_lambda_response, error: ex)
106
112
  end
107
113
 
108
- def send_error_response(lambda_invocation, err, exit_code = nil, runtime_loop_active: true)
114
+ def send_error_response(lambda_invocation, err, exit_code = nil, runtime_loop_active = true)
109
115
  error_object = err.to_lambda_response
110
116
  @lambda_server.send_error_response(
111
117
  request_id: lambda_invocation.request_id,
@@ -120,7 +126,7 @@ module AwsLambdaRuntimeInterfaceClient
120
126
  end
121
127
 
122
128
  # Helper class to for mutating std logger with TelemetryLog
123
- class TelemetryLoggingHelper
129
+ class TelemetryLogger
124
130
 
125
131
  ENV_VAR_TELEMETRY_LOG_FD = '_LAMBDA_TELEMETRY_LOG_FD'
126
132
 
@@ -132,40 +138,32 @@ module AwsLambdaRuntimeInterfaceClient
132
138
  end
133
139
  end
134
140
 
135
- def initialize(telemetry_log_fd, path_to_fd='/proc/self/fd/')
136
- fd = "#{path_to_fd}#{telemetry_log_fd}"
137
- AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_fd_file = File.open(fd, 'wb')
138
- AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_fd_file.sync = true
141
+ def initialize(telemetry_log_fd)
142
+ fd = telemetry_log_fd.to_i
143
+ AwsLambdaRIC::TelemetryLogger.telemetry_log_fd_file = IO.new(fd, 'wb')
144
+ AwsLambdaRIC::TelemetryLogger.telemetry_log_fd_file.sync = true
139
145
 
140
- AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_sink = TelemetryLogSink.new(file: AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_fd_file)
146
+ AwsLambdaRIC::TelemetryLogger.telemetry_log_sink = TelemetryLogSink.new(file: AwsLambdaRIC::TelemetryLogger.telemetry_log_fd_file)
141
147
 
142
148
  mutate_std_logger
143
149
  mutate_kernel_puts
144
- rescue Errno::ENOENT
150
+ rescue Errno::ENOENT, Errno::EBADF
145
151
  # If File.open() fails, then the mutation won't happen and the default behaviour (print to stdout) will prevail
146
152
  end
147
153
 
154
+ def self.from_env()
155
+ if ENV.key?(ENV_VAR_TELEMETRY_LOG_FD)
156
+ fd = ENV.fetch(AwsLambdaRIC::TelemetryLogger::ENV_VAR_TELEMETRY_LOG_FD)
157
+ ENV.delete(AwsLambdaRIC::TelemetryLogger::ENV_VAR_TELEMETRY_LOG_FD)
158
+ AwsLambdaRIC::TelemetryLogger.new(fd)
159
+ end
160
+ end
161
+
148
162
  private
149
163
 
150
164
  def mutate_std_logger
151
165
  Logger.class_eval do
152
- alias_method :orig_initialize, :initialize
153
- def initialize(logdev, shift_age = 0, shift_size = 1048576, level: 'debug',
154
- progname: nil, formatter: nil, datetime_format: nil,
155
- binmode: false, shift_period_suffix: '%Y%m%d')
156
- # use unpatched constructor if logdev is a filename or an IO Object other than $stdout or $stderr
157
- if logdev && logdev != $stdout && logdev != $stderr
158
- orig_initialize(logdev, shift_age, shift_size, level, progname,
159
- formatter, datetime_format, binmode, shift_period_suffix)
160
- else
161
- self.level = level
162
- self.progname = progname
163
- @default_formatter = LambdaLogFormatter.new
164
- self.datetime_format = datetime_format
165
- self.formatter = formatter
166
- @logdev = AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_sink
167
- end
168
- end
166
+ prepend LoggerPatch
169
167
  end
170
168
  end
171
169
 
@@ -173,7 +171,11 @@ module AwsLambdaRuntimeInterfaceClient
173
171
  Kernel.module_eval do
174
172
  def puts(*arg)
175
173
  msg = arg.flatten.collect { |a| a.to_s.encode('UTF-8') }.join("\n")
176
- AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.telemetry_log_sink.write(msg)
174
+ if msg[-1] != "\n"
175
+ msg += "\n"
176
+ end
177
+ AwsLambdaRIC::TelemetryLogger.telemetry_log_sink.write(msg)
178
+ return nil
177
179
  end
178
180
  end
179
181
  end
@@ -191,4 +193,30 @@ module AwsLambdaRuntimeInterfaceClient
191
193
  @trace_id = trace_id
192
194
  end
193
195
  end
196
+
197
+ class Bootstrap
198
+
199
+ def start
200
+ AwsLambdaRIC::TelemetryLogger::from_env()
201
+ bootstrap_handler
202
+ end
203
+
204
+ def fetch_runtime_server
205
+ ENV.fetch(AwsLambdaRIC::LambdaRunner::ENV_VAR_RUNTIME_API)
206
+ rescue KeyError
207
+ puts 'Failed to get runtime server address from AWS_LAMBDA_RUNTIME_API env variable'
208
+ exit(-2)
209
+ end
210
+
211
+ def bootstrap_handler
212
+ if ENV['_HANDLER'] == nil
213
+ puts 'No handler specified, exiting Runtime Interface Client.'
214
+ exit
215
+ end
216
+ app_root = Dir.pwd
217
+ handler = ENV['_HANDLER']
218
+ lambda_runner = AwsLambdaRIC::LambdaRunner.new(fetch_runtime_server, AwsLambdaRIC::get_user_agent)
219
+ lambda_runner.run(app_root, handler)
220
+ end
221
+ end
194
222
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_lambda_ric
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AWS Lambda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-01 00:00:00.000000000 Z
11
+ date: 2025-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -44,14 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.0.1
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: 6.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.5.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.5.5
55
83
  description: The AWS Lambda Ruby Runtime Interface Client implements the Lambda programming
56
84
  model for Ruby.
57
85
  email:
@@ -61,7 +89,6 @@ extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
91
  - Gemfile
64
- - Gemfile.lock
65
92
  - LICENSE
66
93
  - NOTICE
67
94
  - README.md
@@ -69,18 +96,19 @@ files:
69
96
  - bin/aws_lambda_ric
70
97
  - lib/aws_lambda_ric.rb
71
98
  - lib/aws_lambda_ric/aws_lambda_marshaller.rb
72
- - lib/aws_lambda_ric/bootstrap.rb
73
99
  - lib/aws_lambda_ric/lambda_context.rb
74
100
  - lib/aws_lambda_ric/lambda_errors.rb
75
101
  - lib/aws_lambda_ric/lambda_handler.rb
76
102
  - lib/aws_lambda_ric/lambda_log_formatter.rb
77
103
  - lib/aws_lambda_ric/lambda_logger.rb
78
104
  - lib/aws_lambda_ric/lambda_server.rb
105
+ - lib/aws_lambda_ric/logger_patch.rb
79
106
  - lib/aws_lambda_ric/telemetry_log_sink.rb
80
107
  - lib/aws_lambda_ric/version.rb
81
108
  - lib/aws_lambda_ric/xray_cause.rb
82
109
  homepage: https://github.com/aws/aws-lambda-ruby-runtime-interface-client
83
- licenses: []
110
+ licenses:
111
+ - Apache-2.0
84
112
  metadata: {}
85
113
  post_install_message:
86
114
  rdoc_options: []
@@ -90,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
118
  requirements:
91
119
  - - ">="
92
120
  - !ruby/object:Gem::Version
93
- version: '0'
121
+ version: '3.0'
94
122
  required_rubygems_version: !ruby/object:Gem::Requirement
95
123
  requirements:
96
124
  - - ">="
data/Gemfile.lock DELETED
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- aws_lambda_ric (1.0.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (5.14.2)
10
- rake (10.5.0)
11
-
12
- PLATFORMS
13
- ruby
14
-
15
- DEPENDENCIES
16
- aws_lambda_ric!
17
- bundler (>= 2.0)
18
- minitest (~> 5.0)
19
- rake (~> 10.0)
20
-
21
- BUNDLED WITH
22
- 2.2.0.rc.2
@@ -1,38 +0,0 @@
1
- require_relative '../aws_lambda_ric'
2
-
3
- # Bootstrap runtime
4
- module Bootstrap
5
-
6
- def self.start
7
- bootstrap_telemetry_log_sink
8
- bootstrap_handler
9
- end
10
-
11
- def self.fetch_runtime_server
12
- ENV.fetch(AwsLambdaRuntimeInterfaceClient::LambdaRunner::ENV_VAR_RUNTIME_API)
13
- rescue KeyError
14
- puts 'Failed to get runtime server address from AWS_LAMBDA_RUNTIME_API env variable'
15
- exit(-2)
16
- end
17
-
18
- def self.bootstrap_telemetry_log_sink(path_to_fd='/proc/self/fd/')
19
- fd = ENV.fetch(AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper::ENV_VAR_TELEMETRY_LOG_FD)
20
- ENV.delete(AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper::ENV_VAR_TELEMETRY_LOG_FD)
21
- AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.new(fd, path_to_fd)
22
- rescue KeyError
23
- puts 'Skipped bootstraping TelemetryLog'
24
- end
25
-
26
- def self.bootstrap_handler
27
- if ARGV.empty?
28
- puts 'No handler specified, exiting Runtime Interface Client.'
29
- exit
30
- end
31
- app_root = Dir.pwd
32
- handler = ARGV[0]
33
- lambda_runner = AwsLambdaRuntimeInterfaceClient::LambdaRunner.new(fetch_runtime_server)
34
- puts "Executing '#{handler}' in function directory '#{app_root}'"
35
- lambda_runner.run(app_root, handler)
36
- end
37
-
38
- end