@aws-cdk/aws-elasticache-alpha 2.218.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,421 @@
1
+ # ElastiCache CDK Construct Library
2
+ <!--BEGIN STABILITY BANNER-->
3
+
4
+ ---
5
+
6
+ ![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
7
+
8
+ > The APIs of higher level constructs in this module are experimental and under active development.
9
+ > They are subject to non-backward compatible changes or removal in any future version. These are
10
+ > not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
11
+ > announced in the release notes. This means that while you may use them, you may need to update
12
+ > your source code when upgrading to a newer version of this package.
13
+
14
+ ---
15
+
16
+ <!--END STABILITY BANNER-->
17
+
18
+ This module has constructs for [Amazon ElastiCache](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/WhatIs.html).
19
+
20
+ * The `ServerlessCache` construct facilitates the creation and management of serverless cache.
21
+ * The `User` and `UserGroup` constructs facilitate the creation and management of users for the cache.
22
+
23
+ ## Serverless Cache
24
+
25
+ Amazon ElastiCache Serverless is a serverless option that automatically scales cache capacity based on application traffic patterns. You can create a serverless cache using the `ServerlessCache` construct:
26
+
27
+ ```ts
28
+ const vpc = new ec2.Vpc(this, 'VPC');
29
+
30
+ const cache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
31
+ vpc,
32
+ });
33
+ ```
34
+
35
+ ### Connecting to serverless cache
36
+
37
+ To control who can access the serverless cache by the security groups, use the `.connections` attribute.
38
+
39
+ The serverless cache has a default port `6379`.
40
+
41
+ This example allows an EC2 instance to connect to the serverless cache:
42
+
43
+ ```ts
44
+ declare const serverlessCache: elasticache.ServerlessCache;
45
+ declare const instance: ec2.Instance;
46
+
47
+ // allow the EC2 instance to connect to serverless cache on default port 6379
48
+ serverlessCache.connections.allowDefaultPortFrom(instance);
49
+ ```
50
+
51
+ ### Cache usage limits
52
+
53
+ You can configure usage limits on both cache data storage and ECPU/second for your cache to control costs and ensure predictable performance.
54
+
55
+ **Configuration options:**
56
+
57
+ * **Maximum limits**: Ensure your cache usage never exceeds the configured maximum
58
+ * **Minimum limits**: Reserve a baseline level of resources for consistent performance
59
+ * **Both**: Define a range where your cache usage will operate
60
+
61
+ For more infomation, see [Setting scaling limits to manage costs](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Scaling.html#Pre-Scaling).
62
+
63
+ ```ts
64
+ declare const vpc: ec2.Vpc;
65
+
66
+ const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
67
+ engine: elasticache.CacheEngine.VALKEY_LATEST,
68
+ vpc,
69
+ cacheUsageLimits: {
70
+ // cache data storage limits (GB)
71
+ dataStorageMinimumSize: Size.gibibytes(2), // minimum: 1GB
72
+ dataStorageMaximumSize: Size.gibibytes(3), // maximum: 5000GB
73
+ // rate limits (ECPU/second)
74
+ requestRateLimitMinimum: 1000, // minimum: 1000
75
+ requestRateLimitMaximum: 10000, // maximum: 15000000
76
+ },
77
+ });
78
+ ```
79
+
80
+ ### Backups and restore
81
+
82
+ You can enable automatic backups for serverless cache.
83
+ When automatic backups are enabled, ElastiCache creates a backup of the cache on a daily basis.
84
+
85
+ Also you can set the backup window for any time when it's most convenient.
86
+ If you don't specify a backup window, ElastiCache assigns one automatically.
87
+
88
+ For more information, see [Scheduling automatic backups](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/backups-automatic.html).
89
+
90
+ To enable automatic backups, set the `backupRetentionLimit` property. You can also specify the snapshot creation time by setting `backupTime` property:
91
+
92
+ ```ts
93
+ declare const vpc: ec2.Vpc;
94
+
95
+ const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
96
+ backup: {
97
+ // enable automatic backups and set the retention period to 6 days
98
+ backupRetentionLimit: 6,
99
+ // set the backup window to 9:00 AM UTC
100
+ backupTime: events.Schedule.cron({
101
+ hour: '9',
102
+ minute: '0',
103
+ }),
104
+ },
105
+ vpc,
106
+ });
107
+ ```
108
+
109
+ You can create a final backup by setting `backupNameBeforeDeletion` property.
110
+
111
+ ```ts
112
+ declare const vpc: ec2.Vpc;
113
+
114
+ const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
115
+ engine: elasticache.CacheEngine.VALKEY_LATEST,
116
+ backup: {
117
+ // set a backup name before deleting a cache
118
+ backupNameBeforeDeletion: "my-final-backup-name",
119
+ },
120
+ vpc,
121
+ });
122
+ ```
123
+
124
+ You can restore from backups by setting snapshot ARNs to `backupArnsToRestore` property:
125
+
126
+ ```ts
127
+ declare const vpc: ec2.Vpc;
128
+
129
+ const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
130
+ engine: elasticache.CacheEngine.VALKEY_LATEST,
131
+ backup: {
132
+ // set the backup(s) to restore
133
+ backupArnsToRestore: ['arn:aws:elasticache:us-east-1:123456789012:serverlesscachesnapshot:my-final-backup-name'],
134
+ },
135
+ vpc,
136
+ });
137
+ ```
138
+
139
+ ### Encryption at rest
140
+
141
+ At-rest encryption is always enabled for Serverless Cache. There are two encryption options:
142
+
143
+ * **Default**: When no `kmsKey` is specified (left as `undefined`), AWS owned KMS keys are used automatically
144
+ * **Customer Managed Key**: Create a KMS key first, then pass it to the cache via the `kmsKey` property
145
+
146
+ ### Customer Managed Key for encryption at rest
147
+
148
+ ElastiCache supports symmetric Customer Managed key (CMK) for encryption at rest.
149
+
150
+ For more information, see [Using customer managed keys from AWS KMS](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/at-rest-encryption.html#using-customer-managed-keys-for-elasticache-security).
151
+
152
+ To use CMK, set your CMK to the `kmsKey` property:
153
+
154
+ ```ts
155
+ import { Key } from 'aws-cdk-lib/aws-kms';
156
+
157
+ declare const kmsKey: Key;
158
+ declare const vpc: ec2.Vpc;
159
+
160
+ const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
161
+ engine: elasticache.CacheEngine.VALKEY_LATEST,
162
+ serverlessCacheName: 'my-serverless-cache',
163
+ vpc,
164
+ // set Customer Managed Key
165
+ kmsKey,
166
+ });
167
+ ```
168
+
169
+ ### Metrics and monitoring
170
+
171
+ You can monitor your serverless cache using CloudWatch Metrics via the `metric` method.
172
+
173
+ For more information about serverless cache metrics, see [Serverless metrics and events for Valkey and Redis OSS](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/serverless-metrics-events-redis.html) and [Serverless metrics and events for Memcached](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/serverless-metrics-events.memcached.html).
174
+
175
+ ```ts
176
+ declare const serverlessCache: elasticache.ServerlessCache;
177
+
178
+ // The 5 minutes average of the total number of successful read-only key lookups in the cache.
179
+ const cacheHits = serverlessCache.metricCacheHitCount();
180
+
181
+ // The 5 minutes average of the total number of bytes used by the data stored in the cache.
182
+ const bytesUsedForCache = serverlessCache.metricDataStored();
183
+
184
+ // The 5 minutes average of the total number of ElastiCacheProcessingUnits (ECPUs) consumed by the requests executed on the cache.
185
+ const elastiCacheProcessingUnits = serverlessCache.metricProcessingUnitsConsumed();
186
+
187
+ // Create an alarm for ECPUs.
188
+ elastiCacheProcessingUnits.createAlarm(this, 'ElastiCacheProcessingUnitsAlarm', {
189
+ threshold: 50,
190
+ evaluationPeriods: 1,
191
+ });
192
+ ```
193
+
194
+ ### Import an existing serverless cache
195
+
196
+ To import an existing ServerlessCache, use the `ServerlessCache.fromServerlessCacheAttributes` method:
197
+
198
+ ```ts
199
+ declare const securityGroup: ec2.SecurityGroup;
200
+
201
+ const importedServerlessCache = elasticache.ServerlessCache.fromServerlessCacheAttributes(this, 'ImportedServerlessCache', {
202
+ serverlessCacheName: 'my-serverless-cache',
203
+ securityGroups: [securityGroup],
204
+ });
205
+ ```
206
+
207
+ ## User and User Group
208
+
209
+ Setup required properties and create:
210
+
211
+ ```ts
212
+ const newDefaultUser = new elasticache.NoPasswordUser(this, 'NoPasswordUser', {
213
+ userId: 'default',
214
+ accessControl: elasticache.AccessControl.fromAccessString("on ~* +@all"),
215
+ })
216
+
217
+ const userGroup = new elasticache.UserGroup(this, 'UserGroup', {
218
+ users: [newDefaultUser],
219
+ });
220
+ ```
221
+
222
+ ### RBAC
223
+
224
+ In Valkey 7.2 and onward and Redis OSS 6.0 onward you can use a feature called Role-Based Access Control (RBAC). RBAC is also the only way to control access to serverless caches.
225
+
226
+ RBAC enables you to control cache access through user groups. These user groups are designed as a way to organize access to caches.
227
+
228
+ For more information, see [Role-Based Access Control (RBAC)](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Clusters.RBAC.html).
229
+
230
+ To enable RBAC for ElastiCache with Valkey or Redis OSS, you take the following steps:
231
+
232
+ * Create users.
233
+ * Create a user group and add users to the user group.
234
+ * Assign the user group to a cache.
235
+
236
+ ### Create users
237
+
238
+ First, you need to create users by using `IamUser`, `PasswordUser` or `NoPasswordUser` construct.
239
+
240
+ With RBAC, you create users and assign them specific permissions by using `accessString` property.
241
+
242
+ For more information, see [Specifying Permissions Using an Access String](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Clusters.RBAC.html#Access-string).
243
+
244
+ You can create an IAM-enabled user by using `IamUser` construct:
245
+
246
+ ```ts
247
+ const user = new elasticache.IamUser(this, 'User', {
248
+ // set user engine
249
+ engine: elasticache.UserEngine.REDIS,
250
+
251
+ // set user id
252
+ userId: 'my-user',
253
+
254
+ // set username
255
+ userName: 'my-user',
256
+
257
+ // set access string
258
+ accessControl: elasticache.AccessControl.fromAccessString("on ~* +@all"),
259
+ });
260
+ ```
261
+
262
+ > NOTE: IAM-enabled users must have matching user id and username. For more information, see [Limitations](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/auth-iam.html). The construct can set automatically the username to be the same as the user id.
263
+
264
+ If you want to create a password authenticated user, use `PasswordUser` construct:
265
+
266
+ ```ts
267
+ const user = new elasticache.PasswordUser(this, 'User', {
268
+ // set user engine
269
+ engine: elasticache.UserEngine.VALKEY,
270
+
271
+ // set user id
272
+ userId: 'my-user-id',
273
+
274
+ // set access string
275
+ accessControl: elasticache.AccessControl.fromAccessString("on ~* +@all"),
276
+
277
+ // set username
278
+ userName: 'my-user-name',
279
+
280
+ // set up to two passwords
281
+ passwords: [
282
+ // "SecretIdForPassword" is the secret id for the password
283
+ SecretValue.secretsManager('SecretIdForPassword'),
284
+ // "AnotherSecretIdForPassword" is the secret id for the password
285
+ SecretValue.secretsManager('AnotherSecretIdForPassword'),
286
+ ],
287
+ });
288
+ ```
289
+
290
+ You can also create a no password required user by using `NoPasswordUser` construct:
291
+
292
+ ```ts
293
+ const user = new elasticache.NoPasswordUser(this, 'User', {
294
+ // set user engine
295
+ engine: elasticache.UserEngine.REDIS,
296
+
297
+ // set user id
298
+ userId: 'my-user-id',
299
+
300
+ // set access string
301
+ accessControl: elasticache.AccessControl.fromAccessString("on ~* +@all"),
302
+
303
+ // set username
304
+ userName: 'my-user-name',
305
+ });
306
+ ```
307
+
308
+ ### Default user
309
+
310
+ ElastiCache automatically creates a default user with both a user ID and username set to `default`. This default user cannot be modified or deleted. The user is created as a no password authentication user.
311
+
312
+ This user is intended for compatibility with the default behavior of previous Redis OSS versions and has an access string that permits it to call all commands and access all keys.
313
+
314
+ To use this automatically created default user in CDK, you can import it using `NoPasswordUser.fromUserAttributes` method. For more information on import methods, see the [Import an existing user and user group](#import-an-existing-user-and-user-group) section.
315
+
316
+ To add proper access control to a cache, replace the default user with a new one that is either disabled by setting the `accessString` to `off -@all` or secured with a strong password.
317
+
318
+ To change the default user, create a new default user with the username set to `default`. You can then swap it with the original default user.
319
+
320
+ For more information, see [Applying RBAC to a Cache for ElastiCache with Valkey or Redis OSS](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Clusters.RBAC.html#rbac-using).
321
+
322
+ If you want to create a new default user, `userName` must be `default` and `userId` must not be `default` by using `NoPasswordUser` or `PasswordUser`:
323
+
324
+ ```ts
325
+ // use the original `default` user by using import method
326
+ const defaultUser = elasticache.NoPasswordUser.fromUserAttributes(this, 'DefaultUser', {
327
+ // userId and userName must be 'default'
328
+ userId: 'default',
329
+ });
330
+
331
+ // create a new default user
332
+ const newDefaultUser = new elasticache.NoPasswordUser(this, 'NewDefaultUser', {
333
+ // new default user id must not be 'default'
334
+ userId: 'new-default',
335
+ // new default username must be 'default'
336
+ userName: 'default',
337
+ // set access string
338
+ accessControl: elasticache.AccessControl.fromAccessString("on ~* +@all"),
339
+ });
340
+ ```
341
+
342
+ > NOTE: You can't create a new default user using `IamUser` because an IAM-enabled user's username and user ID cannot be different.
343
+
344
+ ### Add users to the user group
345
+
346
+ Next, use the `UserGroup` construct to create a user group and add users to it.
347
+ Ensure that you include either the original default user or a new default user:
348
+
349
+ ```ts
350
+ declare const newDefaultUser: elasticache.IUser;
351
+ declare const user: elasticache.IUser;
352
+ declare const anotherUser: elasticache.IUser;
353
+
354
+ const userGroup = new elasticache.UserGroup(this, 'UserGroup', {
355
+ // add users including default user
356
+ users: [newDefaultUser, user],
357
+ });
358
+
359
+ // you can also add a user by using addUser method
360
+ userGroup.addUser(anotherUser);
361
+ ```
362
+
363
+ ### Assign user group
364
+
365
+ Finally, assign a user group to cache:
366
+
367
+ ```ts
368
+ declare const vpc: ec2.Vpc;
369
+ declare const userGroup: elasticache.UserGroup;
370
+
371
+ const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
372
+ engine: elasticache.CacheEngine.VALKEY_LATEST,
373
+ serverlessCacheName: 'my-serverless-cache',
374
+ vpc,
375
+ // assign User Group
376
+ userGroup,
377
+ });
378
+
379
+ ```
380
+
381
+ ### Grant permissions to IAM-enabled users
382
+
383
+ If you create IAM-enabled users, `"elasticache:Connect"` action must be allowed for the users and cache.
384
+
385
+ > NOTE: You don't need grant permissions to no password required users or password authentication users.
386
+
387
+ For more information, see [Authenticating with IAM](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/auth-iam.html).
388
+
389
+ To grant permissions, you can use the `grantConnect` method in `IamUser` and `ServerlessCache` constructs:
390
+
391
+ ```ts
392
+ declare const user: elasticache.IamUser;
393
+ declare const serverlessCache: elasticache.ServerlessCache;
394
+ declare const role: iam.Role;
395
+
396
+ // grant "elasticache:Connect" action permissions to role
397
+ user.grantConnect(role);
398
+ serverlessCache.grantConnect(role);
399
+ ```
400
+
401
+ ### Import an existing user and user group
402
+
403
+ You can import an existing user and user group by using import methods:
404
+
405
+ ```ts
406
+ const stack = new Stack();
407
+
408
+ const importedIamUser = elasticache.IamUser.fromUserId(this, 'ImportedIamUser', 'my-iam-user-id');
409
+
410
+ const importedPasswordUser = elasticache.PasswordUser.fromUserAttributes(stack, 'ImportedPasswordUser', {
411
+ userId: 'my-password-user-id',
412
+ });
413
+
414
+ const importedNoPasswordUser = elasticache.NoPasswordUser.fromUserAttributes(stack, 'ImportedNoPasswordUser', {
415
+ userId: 'my-no-password-user-id',
416
+ });
417
+
418
+ const importedUserGroup = elasticache.UserGroup.fromUserGroupAttributes(this, 'ImportedUserGroup', {
419
+ userGroupName: 'my-user-group-name'
420
+ });
421
+ ```
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Engine type for ElastiCache users and user groups
3
+ */
4
+ export declare enum UserEngine {
5
+ /**
6
+ * Valkey engine
7
+ */
8
+ VALKEY = "valkey",
9
+ /**
10
+ * Redis engine
11
+ */
12
+ REDIS = "redis"
13
+ }
package/lib/common.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserEngine = void 0;
4
+ /**
5
+ * Engine type for ElastiCache users and user groups
6
+ */
7
+ var UserEngine;
8
+ (function (UserEngine) {
9
+ /**
10
+ * Valkey engine
11
+ */
12
+ UserEngine["VALKEY"] = "valkey";
13
+ /**
14
+ * Redis engine
15
+ */
16
+ UserEngine["REDIS"] = "redis";
17
+ })(UserEngine || (exports.UserEngine = UserEngine = {}));
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiY29tbW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOztHQUVHO0FBQ0gsSUFBWSxVQVVYO0FBVkQsV0FBWSxVQUFVO0lBQ3BCOztPQUVHO0lBQ0gsK0JBQWlCLENBQUE7SUFFakI7O09BRUc7SUFDSCw2QkFBZSxDQUFBO0FBQ2pCLENBQUMsRUFWVyxVQUFVLDBCQUFWLFVBQVUsUUFVckIiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEVuZ2luZSB0eXBlIGZvciBFbGFzdGlDYWNoZSB1c2VycyBhbmQgdXNlciBncm91cHNcbiAqL1xuZXhwb3J0IGVudW0gVXNlckVuZ2luZSB7XG4gIC8qKlxuICAgKiBWYWxrZXkgZW5naW5lXG4gICAqL1xuICBWQUxLRVkgPSAndmFsa2V5JyxcblxuICAvKipcbiAgICogUmVkaXMgZW5naW5lXG4gICAqL1xuICBSRURJUyA9ICdyZWRpcycsXG59XG4iXX0=
@@ -0,0 +1,79 @@
1
+ import { Construct } from 'constructs';
2
+ import { UserEngine } from './common';
3
+ import { UserBase, UserBaseProps } from './user-base';
4
+ import * as iam from 'aws-cdk-lib/aws-iam';
5
+ /**
6
+ * Properties for defining an ElastiCache user with IAM authentication.
7
+ */
8
+ export interface IamUserProps extends UserBaseProps {
9
+ /**
10
+ * The name of the user.
11
+ *
12
+ * @default - Same as userId.
13
+ */
14
+ readonly userName?: string;
15
+ }
16
+ /**
17
+ * Define an ElastiCache user with IAM authentication.
18
+ *
19
+ * @resource AWS::ElastiCache::User
20
+ */
21
+ export declare class IamUser extends UserBase {
22
+ /**
23
+ * Uniquely identifies this class.
24
+ */
25
+ static readonly PROPERTY_INJECTION_ID: string;
26
+ /**
27
+ * Return whether the given object is an `IamUser`.
28
+ */
29
+ static isIamUser(x: any): x is IamUser;
30
+ /**
31
+ * The engine for the user.
32
+ */
33
+ readonly engine?: UserEngine;
34
+ /**
35
+ * The user's ID.
36
+ *
37
+ * @attribute
38
+ */
39
+ readonly userId: string;
40
+ /**
41
+ * The user's name.
42
+ * For IAM authentication userName must be equal to userId.
43
+ *
44
+ * @attribute
45
+ */
46
+ readonly userName?: string;
47
+ /**
48
+ * The access string that defines the user's permissions.
49
+ */
50
+ readonly accessString: string;
51
+ /**
52
+ * The user's ARN.
53
+ *
54
+ * @attribute
55
+ */
56
+ readonly userArn: string;
57
+ /**
58
+ * The user's status.
59
+ * Can be 'active', 'modifying', 'deleting'.
60
+ *
61
+ * @attribute
62
+ */
63
+ readonly userStatus: string;
64
+ private readonly resource;
65
+ constructor(scope: Construct, id: string, props: IamUserProps);
66
+ /**
67
+ * Grant connect permissions to the given IAM identity.
68
+ *
69
+ * @param grantee The IAM identity to grant permissions to.
70
+ */
71
+ grantConnect(grantee: iam.IGrantable): iam.Grant;
72
+ /**
73
+ * Grant the given identity custom permissions.
74
+ *
75
+ * @param grantee The IAM identity to grant permissions to.
76
+ * @param actions The actions to grant.
77
+ */
78
+ grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant;
79
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var _a;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.IamUser = void 0;
11
+ const jsiiDeprecationWarnings = require("../.warnings.jsii.js");
12
+ const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
13
+ const common_1 = require("./common");
14
+ const aws_elasticache_1 = require("aws-cdk-lib/aws-elasticache");
15
+ const user_base_1 = require("./user-base");
16
+ const iam = require("aws-cdk-lib/aws-iam");
17
+ const core_1 = require("aws-cdk-lib/core");
18
+ const metadata_resource_1 = require("aws-cdk-lib/core/lib/metadata-resource");
19
+ const prop_injectable_1 = require("aws-cdk-lib/core/lib/prop-injectable");
20
+ const ELASTICACHE_IAMUSER_SYMBOL = Symbol.for('@aws-cdk/aws-elasticache.IamUser');
21
+ /**
22
+ * Define an ElastiCache user with IAM authentication.
23
+ *
24
+ * @resource AWS::ElastiCache::User
25
+ */
26
+ let IamUser = class IamUser extends user_base_1.UserBase {
27
+ /**
28
+ * Return whether the given object is an `IamUser`.
29
+ */
30
+ static isIamUser(x) {
31
+ return x !== null && typeof (x) === 'object' && ELASTICACHE_IAMUSER_SYMBOL in x;
32
+ }
33
+ constructor(scope, id, props) {
34
+ super(scope, id);
35
+ try {
36
+ jsiiDeprecationWarnings._aws_cdk_aws_elasticache_alpha_IamUserProps(props);
37
+ }
38
+ catch (error) {
39
+ if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
40
+ Error.captureStackTrace(error, IamUser);
41
+ }
42
+ throw error;
43
+ }
44
+ // Enhanced CDK Analytics Telemetry
45
+ (0, metadata_resource_1.addConstructMetadata)(this, props);
46
+ this.engine = props.engine ?? common_1.UserEngine.VALKEY;
47
+ this.userId = props.userId;
48
+ this.userName = props.userName ?? props.userId;
49
+ this.accessString = props.accessControl.accessString;
50
+ if (this.userName !== this.userId) {
51
+ throw new core_1.ValidationError('For IAM authentication, userName must be equal to userId.', this);
52
+ }
53
+ this.resource = new aws_elasticache_1.CfnUser(this, 'Resource', {
54
+ engine: this.engine,
55
+ userId: props.userId,
56
+ userName: this.userName,
57
+ accessString: this.accessString,
58
+ authenticationMode: {
59
+ Type: 'iam',
60
+ },
61
+ noPasswordRequired: false,
62
+ passwords: undefined,
63
+ });
64
+ this.userArn = this.resource.attrArn;
65
+ this.userStatus = this.resource.attrStatus;
66
+ Object.defineProperty(this, ELASTICACHE_IAMUSER_SYMBOL, { value: true });
67
+ }
68
+ /**
69
+ * Grant connect permissions to the given IAM identity.
70
+ *
71
+ * @param grantee The IAM identity to grant permissions to.
72
+ */
73
+ grantConnect(grantee) {
74
+ return this.grant(grantee, 'elasticache:Connect');
75
+ }
76
+ /**
77
+ * Grant the given identity custom permissions.
78
+ *
79
+ * @param grantee The IAM identity to grant permissions to.
80
+ * @param actions The actions to grant.
81
+ */
82
+ grant(grantee, ...actions) {
83
+ return iam.Grant.addToPrincipal({
84
+ grantee,
85
+ actions,
86
+ resourceArns: [this.userArn],
87
+ });
88
+ }
89
+ };
90
+ exports.IamUser = IamUser;
91
+ _a = JSII_RTTI_SYMBOL_1;
92
+ IamUser[_a] = { fqn: "@aws-cdk/aws-elasticache-alpha.IamUser", version: "2.218.0-alpha.0" };
93
+ /**
94
+ * Uniquely identifies this class.
95
+ */
96
+ IamUser.PROPERTY_INJECTION_ID = 'aws-cdk-lib.aws-elasticache.IamUser';
97
+ __decorate([
98
+ (0, metadata_resource_1.MethodMetadata)()
99
+ ], IamUser.prototype, "grantConnect", null);
100
+ __decorate([
101
+ (0, metadata_resource_1.MethodMetadata)()
102
+ ], IamUser.prototype, "grant", null);
103
+ exports.IamUser = IamUser = __decorate([
104
+ prop_injectable_1.propertyInjectable
105
+ ], IamUser);
106
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWFtLXVzZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpYW0tdXNlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFDQSxxQ0FBc0M7QUFDdEMsaUVBQXNEO0FBQ3RELDJDQUFzRDtBQUN0RCwyQ0FBMkM7QUFDM0MsMkNBQW1EO0FBQ25ELDhFQUE4RjtBQUM5RiwwRUFBMEU7QUFFMUUsTUFBTSwwQkFBMEIsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUF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lkZW50aXR5LlxuICAgKlxuICAgKiBAcGFyYW0gZ3JhbnRlZSBUaGUgSUFNIGlkZW50aXR5IHRvIGdyYW50IHBlcm1pc3Npb25zIHRvLlxuICAgKi9cbiAgQE1ldGhvZE1ldGFkYXRhKClcbiAgcHVibGljIGdyYW50Q29ubmVjdChncmFudGVlOiBpYW0uSUdyYW50YWJsZSk6IGlhbS5HcmFudCB7XG4gICAgcmV0dXJuIHRoaXMuZ3JhbnQoZ3JhbnRlZSwgJ2VsYXN0aWNhY2hlOkNvbm5lY3QnKTtcbiAgfVxuXG4gIC8qKlxuICAgKiBHcmFudCB0aGUgZ2l2ZW4gaWRlbnRpdHkgY3VzdG9tIHBlcm1pc3Npb25zLlxuICAgKlxuICAgKiBAcGFyYW0gZ3JhbnRlZSBUaGUgSUFNIGlkZW50aXR5IHRvIGdyYW50IHBlcm1pc3Npb25zIHRvLlxuICAgKiBAcGFyYW0gYWN0aW9ucyBUaGUgYWN0aW9ucyB0byBncmFudC5cbiAgICovXG4gIEBNZXRob2RNZXRhZGF0YSgpXG4gIHB1YmxpYyBncmFudChncmFudGVlOiBpYW0uSUdyYW50YWJsZSwgLi4uYWN0aW9uczogc3RyaW5nW10pOiBpYW0uR3JhbnQge1xuICAgIHJldHVybiBpYW0uR3JhbnQuYWRkVG9QcmluY2lwYWwoe1xuICAgICAgZ3JhbnRlZSxcbiAgICAgIGFjdGlvbnMsXG4gICAgICByZXNvdXJjZUFybnM6IFt0aGlzLnVzZXJBcm5dLFxuICAgIH0pO1xuICB9XG59XG4iXX0=
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './common';
2
+ export * from './user-group';
3
+ export * from './user-base';
4
+ export * from './iam-user';
5
+ export * from './password-user';
6
+ export * from './no-password-user';
7
+ export * from './serverless-cache-base';
8
+ export * from './serverless-cache';