| 1 | import type * as Effect from "effect/Effect"; |
| 2 | import * as Binding from "../../Binding.ts"; |
| 3 | import type { Input } from "../../Input.ts"; |
| 4 | import type { RuntimeContext } from "../../RuntimeContext.ts"; |
| 5 | import { connectEnvPrefix as makeConnectEnvPrefix } from "../Connection/internal.ts"; |
| 6 | import type { SecurityGroupId } from "../EC2/SecurityGroup.ts"; |
| 7 | import type { SubnetId } from "../EC2/Subnet.ts"; |
| 8 | import type { CacheCluster } from "./CacheCluster.ts"; |
| 9 | |
| 10 | export interface CacheClusterConnectionInfo { |
| 11 | endpoints: Array<{ address: string; port: number }>; |
| 12 | tls: boolean; |
| 13 | } |
| 14 | |
| 15 | export interface ConnectCacheClusterOptions { |
| 16 | subnetIds?: Input<SubnetId[]>; |
| 17 | securityGroupIds?: Input<SecurityGroupId[]>; |
| 18 | } |
| 19 | |
| 20 | export const cacheClusterConnectEnvPrefix = (logicalId: string) => |
| 21 | makeConnectEnvPrefix("ELASTICACHE", logicalId); |
| 22 | |
| 23 | /** |
| 24 | * Runtime binding for a provisioned Memcached cluster. |
| 25 | * |
| 26 | * At deploy time it publishes all node endpoints as |
| 27 | * `ELASTICACHE_{LOGICAL_ID}_ENDPOINTS` on the host Function. Passing VPC |
| 28 | * options attaches the host Lambda to the cache network. ElastiCache data |
| 29 | * plane access is controlled by security groups, not IAM. |
| 30 | * |
| 31 | * ### Connecting from a Lambda |
| 32 | * **Example:** Resolve Memcached node endpoints |
| 33 | * ```typescript |
| 34 | * const connect = yield* AWS.ElastiCache.ConnectCacheCluster(cache, { |
| 35 | * subnetIds: privateSubnetIds, |
| 36 | * securityGroupIds: [functionSecurityGroup.groupId], |
| 37 | * }); |
| 38 | * |
| 39 | * // inside the handler: |
| 40 | * const { endpoints } = yield* connect; |
| 41 | * const endpoint = endpoints[0]; |
| 42 | * ``` |
| 43 | * |
| 44 | * @binding |
| 45 | */ |
| 46 | export interface ConnectCacheCluster extends Binding.Service< |
| 47 | ConnectCacheCluster, |
| 48 | "AWS.ElastiCache.ConnectCacheCluster", |
| 49 | ( |
| 50 | cluster: CacheCluster, |
| 51 | options?: ConnectCacheClusterOptions, |
| 52 | ) => Effect.Effect< |
| 53 | Effect.Effect<CacheClusterConnectionInfo, never, RuntimeContext> |
| 54 | > |
| 55 | > {} |
| 56 | export const ConnectCacheCluster = Binding.Service<ConnectCacheCluster>( |
| 57 | "AWS.ElastiCache.ConnectCacheCluster", |
| 58 | ); |