Skip to content

Commit a735ed1

Browse files
committed
feat(aws): added vnd streaming chunk parser
1 parent 9e66799 commit a735ed1

21 files changed

+386
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ delete-me
4545
# generated files
4646
*.rockspec
4747
src/resty/aws/raw-api
48+
.DS_Store

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ Release process:
176176
1. upload using: `VERSION=x.y.z APIKEY=abc... make upload`
177177
1. test installing the rock from LuaRocks
178178

179+
### 1.6.0 (04-Jun-2024)
180+
181+
- feat: update the AWS SDK to v2.1353.0
182+
[117](https://github.com/Kong/lua-resty-aws/pull/117)
179183

180184
### 1.5.0 (20-May-2024)
181185

docs/classes/AWS.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ <h3>Usage:</h3>
151151
</div> <!-- id="main" -->
152152
<div id="about">
153153
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
154-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
154+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
155155
</div> <!-- id="about" -->
156156
</div> <!-- id="container" -->
157157
</body>

docs/classes/ChainableTemporaryCredentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ <h3>Usage:</h3>
147147
</div> <!-- id="main" -->
148148
<div id="about">
149149
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
150-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
150+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
151151
</div> <!-- id="about" -->
152152
</div> <!-- id="container" -->
153153
</body>

docs/classes/CredentialProviderChain.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ <h3>Parameters:</h3>
131131
</div> <!-- id="main" -->
132132
<div id="about">
133133
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
134-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
134+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
135135
</div> <!-- id="about" -->
136136
</div> <!-- id="container" -->
137137
</body>

docs/classes/Credentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ <h3>Returns:</h3>
266266
</div> <!-- id="main" -->
267267
<div id="about">
268268
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
269-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
269+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
270270
</div> <!-- id="about" -->
271271
</div> <!-- id="container" -->
272272
</body>

docs/classes/EC2MetadataCredentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h3>Parameters:</h3>
113113
</div> <!-- id="main" -->
114114
<div id="about">
115115
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
116-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
116+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
117117
</div> <!-- id="about" -->
118118
</div> <!-- id="container" -->
119119
</body>

docs/classes/EnvironmentCredentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ <h3>Parameters:</h3>
122122
</div> <!-- id="main" -->
123123
<div id="about">
124124
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
125-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
125+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
126126
</div> <!-- id="about" -->
127127
</div> <!-- id="container" -->
128128
</body>

docs/classes/RemoteCredentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h3>Parameters:</h3>
113113
</div> <!-- id="main" -->
114114
<div id="about">
115115
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
116-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
116+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
117117
</div> <!-- id="about" -->
118118
</div> <!-- id="container" -->
119119
</body>

docs/classes/SharedFileCredentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h3>Parameters:</h3>
113113
</div> <!-- id="main" -->
114114
<div id="about">
115115
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
116-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
116+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
117117
</div> <!-- id="about" -->
118118
</div> <!-- id="container" -->
119119
</body>

docs/classes/TokenFileWebIdentityCredentials.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ <h3>Parameters:</h3>
128128
</div> <!-- id="main" -->
129129
<div id="about">
130130
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
131-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
131+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
132132
</div> <!-- id="about" -->
133133
</div> <!-- id="container" -->
134134
</body>

docs/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ <h2>Topics</h2>
126126
</div> <!-- id="main" -->
127127
<div id="about">
128128
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
129-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
129+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
130130
</div> <!-- id="about" -->
131131
</div> <!-- id="container" -->
132132
</body>

docs/modules/resty.aws.config.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ <h3>Returns:</h3>
356356
</div> <!-- id="main" -->
357357
<div id="about">
358358
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
359-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
359+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
360360
</div> <!-- id="about" -->
361361
</div> <!-- id="container" -->
362362
</body>

docs/modules/resty.aws.service.rds.signer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ <h3>Usage:</h3>
191191
</div> <!-- id="main" -->
192192
<div id="about">
193193
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
194-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
194+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
195195
</div> <!-- id="about" -->
196196
</div> <!-- id="container" -->
197197
</body>

docs/modules/resty.aws.utils.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ <h3>Returns:</h3>
196196
</div> <!-- id="main" -->
197197
<div id="about">
198198
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
199-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
199+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
200200
</div> <!-- id="about" -->
201201
</div> <!-- id="container" -->
202202
</body>

docs/topics/README.md.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ <h2>History</h2>
289289
<li>test installing the rock from LuaRocks</li>
290290
</ol>
291291

292+
<h3>1.6.0 (04-Jun-2024)</h3>
293+
294+
<ul>
295+
<li>feat: update the AWS SDK to v2.1353.0
296+
<a href="https://github.com/Kong/lua-resty-aws/pull/117">117</a></li>
297+
</ul>
292298

293299
<h3>1.5.0 (20-May-2024)</h3>
294300

@@ -563,7 +569,7 @@ <h3>0.1 (03-Feb-2021) Initial released version</h3>
563569
</div> <!-- id="main" -->
564570
<div id="about">
565571
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
566-
<i style="float:right;">Last updated 2024-05-20 09:07:14 </i>
572+
<i style="float:right;">Last updated 2024-06-04 09:33:12 </i>
567573
</div> <!-- id="about" -->
568574
</div> <!-- id="container" -->
569575
</body>
+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
local tablex = require "pl.tablex"
2+
3+
describe("stream decoder", function()
4+
setup(function()
5+
AWS = require "resty.aws"
6+
end)
7+
8+
teardown(function()
9+
AWS = nil
10+
package.loaded["resty.aws"] = nil
11+
end)
12+
13+
14+
it("decodes multiple messages from a single chunk", function()
15+
local chunk_in_hex = "000000760000005296d5fade0b3a6576656e742d7479706507000c6d65737361676553746172740d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b22726f6c65223a22617373697374616e74227d6fa8c599000001110000005706f176a90b3a6576656e742d74797065070011636f6e74656e74426c6f636b44656c74610d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b22636f6e74656e74426c6f636b496e646578223a302c2264656c7461223a7b2274657874223a2250692028cf80292069732061206d617468656d61746963616c20636f6e7374616e74207468617420726570726573656e7473207468652063697263756d666572656e63652d746f2d6469616d6574657220726174696f206f66206120636972636c652e204974277320617070726f78696d6174656c7920332e31343135392e227d7d7d4e31940000007d00000056e6680fd60b3a6576656e742d74797065070010636f6e74656e74426c6f636b53746f700d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b22636f6e74656e74426c6f636b496e646578223a307db32e4d340000007a00000051ca2c46650b3a6576656e742d7479706507000b6d65737361676553746f700d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b2273746f70526561736f6e223a22656e645f7475726e227d5fbf09fc000000b90000004ee991d99b0b3a6576656e742d747970650700086d657461646174610d3a636f6e74656e742d747970650700106170706c69636174696f6e2f6a736f6e0d3a6d6573736167652d747970650700056576656e747b226d657472696373223a7b226c6174656e63794d73223a313530367d2c227573616765223a7b22696e707574546f6b656e73223a382c226f7574707574546f6b656e73223a33392c22746f74616c546f6b656e73223a34377d7d5ad2dd7b"
16+
local _STREAM = require("resty.aws.stream")
17+
local parser, err = _STREAM:new(chunk_in_hex, true)
18+
19+
if err then
20+
assert.equal(err, nil)
21+
return
22+
end
23+
24+
local messages = {}
25+
26+
while true do
27+
local msg = parser:next_message()
28+
29+
if not msg then
30+
break
31+
end
32+
33+
messages[#messages+1] = msg
34+
end
35+
36+
assert.same(messages, {
37+
{
38+
body = "{\"role\":\"assistant\"}",
39+
headers = {
40+
{
41+
key = ":event-type",
42+
value = "messageStart"
43+
},
44+
{
45+
key = ":content-type",
46+
value = "application/json"
47+
},
48+
{
49+
key = ":message-type",
50+
value = "event"
51+
}
52+
}
53+
},
54+
{
55+
body = "{\"contentBlockIndex\":0,\"delta\":{\"text\":\"Pi (π) is a mathematical constant that represents the circumference-to-diameter ratio of a circle. It's approximately 3.14159.\"}}",
56+
headers = {
57+
{
58+
key = ":event-type",
59+
value = "contentBlockDelta"
60+
},
61+
{
62+
key = ":content-type",
63+
value = "application/json"
64+
},
65+
{
66+
key = ":message-type",
67+
value = "event"
68+
}
69+
}
70+
},
71+
{
72+
body = "{\"contentBlockIndex\":0}",
73+
headers = {
74+
{
75+
key = ":event-type",
76+
value = "contentBlockStop"
77+
},
78+
{
79+
key = ":content-type",
80+
value = "application/json"
81+
},
82+
{
83+
key = ":message-type",
84+
value = "event"
85+
}
86+
}
87+
},
88+
{
89+
body = "{\"stopReason\":\"end_turn\"}",
90+
headers = {
91+
{
92+
key = ":event-type",
93+
value = "messageStop"
94+
},
95+
{
96+
key = ":content-type",
97+
value = "application/json"
98+
},
99+
{
100+
key = ":message-type",
101+
value = "event"
102+
}
103+
}
104+
},
105+
{
106+
body = "{\"metrics\":{\"latencyMs\":1506},\"usage\":{\"inputTokens\":8,\"outputTokens\":39,\"totalTokens\":47}}",
107+
headers = {
108+
{
109+
key = ":event-type",
110+
value = "metadata"
111+
},
112+
{
113+
key = ":content-type",
114+
value = "application/json"
115+
},
116+
{
117+
key = ":message-type",
118+
value = "event"
119+
}
120+
}
121+
}
122+
})
123+
end)
124+
end)

src/resty/aws/request/execute.lua

+17-9
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,22 @@ local function execute_request(signed_request)
5050
tostring(err))
5151
end
5252

53+
local body, body_reader
5354

54-
local body do
55-
if response.has_body then
56-
body, err = response:read_body()
57-
if not body then
58-
return nil, ("failed reading response body from '%s:%s': %s"):format(
59-
tostring(signed_request.host),
60-
tostring(signed_request.port),
61-
tostring(err))
55+
if response.headers["application/vnd.amazon.eventstream"] then
56+
body_reader = response.body_reader
57+
else
58+
local this_body do
59+
if response.has_body then
60+
this_body, err = response:read_body()
61+
if not this_body then
62+
return nil, ("failed reading response body from '%s:%s': %s"):format(
63+
tostring(signed_request.host),
64+
tostring(signed_request.port),
65+
tostring(err))
66+
end
67+
68+
body = this_body
6269
end
6370
end
6471
end
@@ -82,7 +89,8 @@ local function execute_request(signed_request)
8289
status = response.status,
8390
reason = response.reason,
8491
headers = response.headers,
85-
body = body
92+
body = body,
93+
body_reader = body_reader,
8694
}
8795
end
8896

0 commit comments

Comments
 (0)