Update sample to not cause unserializable captures.
MODIFY
aws-ts-url-shortener-cache-http/cache.ts
aws-ts-url-shortener-cache-http/cache.ts
@@ -9,6 +9,9 @@ export class Cache {
private readonly redis: awsx.ecs.FargateService;
private readonly endpoint: pulumi.Output<awsx.elasticloadbalancingv2.ListenerEndpoint>;
+ public get: (key: string) => Promise<string>;
+ public set: (key: string, value: string) => Promise<void>;
+
constructor(name: string, memory: number = 128) {
const pw = config.redisPassword;
const listener = new awsx.elasticloadbalancingv2.NetworkListener(name, { port: 6379 });
@@ -26,10 +29,11 @@ export class Cache {
});
this.endpoint = listener.endpoint;
- }
- public get(key: string): Promise<string> {
- const ep = this.endpoint.get();
+ // Expose get/set as member fields that don't capture 'this'. That way we don't try to
+ // serialize pulumi resources unnecessarily into our lambdas.
+ this.get = key => {
+ const ep = listener.endpoint.get();
console.log(`Getting key '${key}' on Redis@${ep.hostname}:${ep.port}`);
const client = require("redis").createClient(ep.port, ep.hostname, { password: config.redisPassword });
@@ -42,10 +46,10 @@ export class Cache {
}
});
});
- }
+ };
- public set(key: string, value: string): Promise<void> {
- const ep = this.endpoint.get();
+ this.set = (key, value) => {
+ const ep = listener.endpoint.get();
console.log(`Setting key '${key}' to '${value}' on Redis@${ep.hostname}:${ep.port}`);
const client = require("redis").createClient(ep.port, ep.hostname, { password: config.redisPassword });
@@ -59,5 +63,7 @@ export class Cache {
}
});
});
+ };
}
}
+

Update sample to not cause unserializable captures. (#561)