You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Eeach event is processed separetly the handler function.
124
-
// The function must have the following signature:
125
-
fn handler(
126
-
ctx: lambda.Context, // Metadata and utilities
127
-
event: []const u8, // Raw event payload (JSON)
128
-
stream: lambda.Stream, // Response stream
129
-
) !void {
130
-
// Start streaming the response for a given content type.
131
-
try stream.open("text/event-stream");
132
-
133
-
// Append to the streaming buffer.
134
-
try stream.write("data: Message");
135
-
try stream.writeFmt(" number {d}\n\n", .{1});
136
-
137
-
// Publish the buffer to the client.
138
-
try stream.flush();
139
-
140
-
// Wait for half a second.
141
-
std.time.sleep(500_000_000);
142
-
143
-
// Append to streaming buffer and immediatly publish to the client.
144
-
try stream.publish("data: Message number 2\n\n");
145
-
std.time.sleep(100_000_000);
107
+
## Documentation
146
108
147
-
// Publish also supports formatting.
148
-
try stream.publishFmt("data: Message number {d}\n\n", .{3});
109
+
### Build
110
+
This library provides a runtime module that handles the Lambda lifecycle and communication with the execution environment.
111
+
To use it, follow the following requirements:
112
+
- Import the Lambda Runtime module this library provides and wrap a handler function with it.
113
+
- Build an executable named _bootstrap_ and archive it in a Zip file.
114
+
- Use _Amazon Linux 2023_ or any other supported OS-only runtime.
149
115
150
-
// Optionally close the stream.
151
-
try stream.close();
152
-
}
153
-
```
154
-
155
-
## Documentation
116
+
#### Managed Target
117
+
AWS Lambda supports two architectures: _x86_64_ and _arm64_ based on _Graviton2_. In order to build the event handler correctly and to squeeze the best performance, the build target must be configured accordingly.
156
118
157
-
### Build Target
158
-
AWS Lambda provides two architectures for the runtime environment: _x86_64_ and _arm64_ based on _Graviton2_. In order to build the event handler correctly and to squeeze the best performance, the build target must be configured accordingly.
119
+
The mananged target resolver sets the optimal operating system, architecture and specific CPU supported features. Call `lambda.resolveTargetQuery(*std.Build, arch)` to resolve the target for the given architecture (either `.x86` or `.arm`).
159
120
160
-
The mananged target resolver sets the operating system, architecture and specific CPU supported features. It can be utilizes in the build script in two forms:
121
+
To add a CLI configuration option call `lambda.archOption(*std.Build)` the following and pass the result to `lambda.resolveTargetQuery`.
122
+
It can then by set through `-Darch=x86` or `-Darch=arm` (defaults to _x86_ when to manualy used).
161
123
124
+
#### Example Build Script
162
125
```zig
163
126
const std = @import("std");
164
127
const lambda = @import("aws-lambda");
165
128
166
129
pub fn build(b: *std.Build) void {
167
-
// Option A – CLI confuration:
168
-
const arch = lambda.archOption(b);
130
+
const optimize = b.standardOptimizeOption(.{
131
+
.preferred_optimize_mode = .ReleaseFast,
132
+
});
133
+
134
+
// Add an architecture CLI option (or hard code either `.x86` or `.arm`)
0 commit comments