Skip to content

Commit 61f44a3

Browse files
author
Ramisa Alam
committed
feat: add tenant id to invoke context
1 parent b13fef2 commit 61f44a3

6 files changed

+78
-1
lines changed

deps/aws-lambda-cpp-0.2.8.tar.gz

-4.1 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h
2+
index f7cb8ef..833b69d 100644
3+
--- a/include/aws/lambda-runtime/runtime.h
4+
+++ b/include/aws/lambda-runtime/runtime.h
5+
@@ -56,6 +56,11 @@ struct invocation_request {
6+
*/
7+
std::string function_arn;
8+
9+
+ /**
10+
+ * The Tenant ID of the current invocation.
11+
+ */
12+
+ std::string tenant_id;
13+
+
14+
/**
15+
* Function execution deadline counted in milliseconds since the Unix epoch.
16+
*/
17+
diff --git a/src/runtime.cpp b/src/runtime.cpp
18+
index d1e655f..bcc217d 100644
19+
--- a/src/runtime.cpp
20+
+++ b/src/runtime.cpp
21+
@@ -40,6 +40,7 @@ static constexpr auto CLIENT_CONTEXT_HEADER = "lambda-runtime-client-context";
22+
static constexpr auto COGNITO_IDENTITY_HEADER = "lambda-runtime-cognito-identity";
23+
static constexpr auto DEADLINE_MS_HEADER = "lambda-runtime-deadline-ms";
24+
static constexpr auto FUNCTION_ARN_HEADER = "lambda-runtime-invoked-function-arn";
25+
+static constexpr auto TENANT_ID_HEADER = "lambda-runtime-aws-tenant-id";
26+
27+
enum Endpoints {
28+
INIT,
29+
@@ -296,6 +297,11 @@ runtime::next_outcome runtime::get_next()
30+
req.function_arn = std::move(out).get_result();
31+
}
32+
33+
+ out = resp.get_header(TENANT_ID_HEADER);
34+
+ if (out.is_success()) {
35+
+ req.tenant_id = std::move(out).get_result();
36+
+ }
37+
+
38+
out = resp.get_header(DEADLINE_MS_HEADER);
39+
if (out.is_success()) {
40+
auto const& deadline_string = std::move(out).get_result();

scripts/update_dependencies.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ wget -c https://github.com/awslabs/aws-lambda-cpp/archive/refs/tags/v$AWS_LAMBDA
2929
# Apply patches
3030
(
3131
cd aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE && \
32-
patch -p1 < ../patches/aws-lambda-cpp-add-xray-response.patch
32+
patch -p1 < ../patches/aws-lambda-cpp-add-xray-response.patch && \
33+
patch -p1 < ../patches/aws-lambda-cpp-add-tenant-id.patch
3334
)
3435

3536
# Pack again and remove the folder

src/InvokeContext.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const INVOKE_HEADER = {
1818
AWSRequestId: 'lambda-runtime-aws-request-id',
1919
DeadlineMs: 'lambda-runtime-deadline-ms',
2020
XRayTrace: 'lambda-runtime-trace-id',
21+
TenantId: 'lambda-runtime-aws-tenant-id',
2122
};
2223

2324
module.exports = class InvokeContext {
@@ -91,6 +92,7 @@ module.exports = class InvokeContext {
9192
),
9293
invokedFunctionArn: this.headers[INVOKE_HEADER.ARN],
9394
awsRequestId: this.headers[INVOKE_HEADER.AWSRequestId],
95+
tenantId: this.headers[INVOKE_HEADER.TenantId],
9496
getRemainingTimeInMillis: function () {
9597
return deadline - Date.now();
9698
},

src/rapid-client.cc

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class RuntimeApiNextPromiseWorker : public Napi::AsyncWorker {
8282
Napi::String::New(env, "lambda-runtime-cognito-identity"),
8383
Napi::String::New(env, response.cognito_identity.c_str()));
8484
}
85+
if (response.tenant_id != "") {
86+
headers.Set(
87+
Napi::String::New(env, "lambda-runtime-aws-tenant-id"),
88+
Napi::String::New(env, response.tenant_id.c_str()));
89+
}
8590

8691
auto ret = Napi::Object::New(env);
8792
ret.Set(Napi::String::New(env, "bodyJson"), response_data);

test/unit/InvokeContextTest.js

+29
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,32 @@ describe('Getting remaining invoke time', () => {
3535
remainingTime.should.lessThanOrEqual(1000);
3636
});
3737
});
38+
39+
describe('Verifying tenant id', () => {
40+
it('should return undefined if tenant id is not set', () => {
41+
let ctx = new InvokeContext({});
42+
43+
(ctx._headerData().tenantId === undefined).should.be.true();
44+
});
45+
it('should return undefined if tenant id is set to undefined', () => {
46+
let ctx = new InvokeContext({
47+
'lambda-runtime-aws-tenant-id': undefined,
48+
});
49+
50+
(ctx._headerData().tenantId === undefined).should.be.true();
51+
});
52+
it('should return empty if tenant id is set to empty string', () => {
53+
let ctx = new InvokeContext({
54+
'lambda-runtime-aws-tenant-id': '',
55+
});
56+
57+
(ctx._headerData().tenantId === '').should.be.true();
58+
});
59+
it('should return the same id if a valid tenant id is set', () => {
60+
let ctx = new InvokeContext({
61+
'lambda-runtime-aws-tenant-id': 'blue',
62+
});
63+
64+
ctx._headerData().tenantId.should.equal('blue');
65+
});
66+
});

0 commit comments

Comments
 (0)