Skip to content

Commit 34d1512

Browse files
authored
Merge pull request #41 from aws-samples/feature/elasticache-serverless
Feature/elasticache serverless
2 parents 536a192 + d9c59e5 commit 34d1512

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+18696
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ The following are tutorials covering various use cases for [Amazon ElastiCache](
2424

2525
- [Flask Redis Session Management](./webinars/flask-redis-session/) - This is a simple Flask web application that demonstrates user session management using Redis as the session storage.
2626

27+
## DevOps
28+
29+
Deploy infrastructe as code
30+
31+
### AWS CDK [Cloud Development Kit]
32+
33+
#### TypeScript
34+
35+
- [Amazon ElastiCache Serverless for Memached](devops/aws-cdk/typescript/elasticache-serverless-memcached-minimal/README.md)
36+
- [Amazon ElastiCache Serverless for Redis](devops/aws-cdk/typescript/elasticache-serverless-redis-minimal/README.md)
37+
- [Amazon ElastiCache for Redis Cluster Mode Disabled](devops/aws-cdk/typescript/elasticache-redis-cmd/README.md)
38+
2739
---
2840

2941
## Security
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
tmp/*
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Amazon ElastiCache for Redis Cluster Mode Disabled [CDK Stack]
2+
3+
Pre-requisites
4+
- [Git](https://git-scm.com/)
5+
- [NodeJS](https://nodejs.org/en)
6+
- [AWS CDK](https://github.com/aws/aws-cdk)
7+
8+
Clone this repository
9+
```bash
10+
git clone https://github.com/aws-samples/amazon-elasticache-samples.git
11+
```
12+
13+
Enter this folder
14+
```bash
15+
cd devops/aws-cdk/typescript/elasticache-redis-cmd/
16+
```
17+
18+
Install dependencies
19+
```bash
20+
npm install
21+
cdk bootstrap
22+
```
23+
24+
Deploy Amazon ElastiCache for Redis Cluster Mode Disabled
25+
```bash
26+
cdk synth; cdk deploy --require-approval never
27+
```
28+
29+
Cleanup your environment
30+
```bash
31+
cdk destroy -f
32+
```
33+
34+
## How does it work?
35+
36+
Snippet from `src/elasticache-redis-cmd-stack.ts`
37+
38+
```typescript
39+
const elastiCacheRedisCMD = new ElastiCache.CfnReplicationGroup(
40+
this,
41+
elastiCacheRedisCMDName.toLowerCase(),
42+
{
43+
replicationGroupDescription: "ElastiCache for Redis Cluster Mode Enabled CDK",
44+
numCacheClusters: 2,
45+
automaticFailoverEnabled: true,
46+
engine: "redis",
47+
cacheNodeType: "cache.t4g.micro",
48+
cacheSubnetGroupName: elastiCacheSubnetGroup.ref,
49+
securityGroupIds: [elastiCacheSecurityGroup.securityGroupId]
50+
}
51+
);
52+
```
53+
54+
## Useful commands
55+
56+
* `npm run build` compile typescript to js
57+
* `npm run watch` watch for changes and compile
58+
* `npm run test` perform the jest unit tests
59+
* `npx cdk deploy` deploy this stack to your default AWS account/region
60+
* `npx cdk diff` compare deployed stack with current state
61+
* `npx cdk synth` emits the synthesized CloudFormation template
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { ElasticacheRedisCmdStack } from '../src/elasticache-redis-cmd-stack';
5+
6+
const app = new cdk.App();
7+
new ElasticacheRedisCmdStack(app, 'ElasticacheRedisCmdStack', {
8+
/* If you don't specify 'env', this stack will be environment-agnostic.
9+
* Account/Region-dependent features and context lookups will not work,
10+
* but a single synthesized template can be deployed anywhere. */
11+
12+
/* Uncomment the next line to specialize this stack for the AWS Account
13+
* and Region that are implied by the current CLI configuration. */
14+
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
15+
16+
/* Uncomment the next line if you know exactly what Account and Region you
17+
* want to deploy the stack to. */
18+
// env: { account: '123456789012', region: 'us-east-1' },
19+
20+
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
21+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/elasticache-redis-cmd.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41+
"@aws-cdk/aws-route53-patters:useCertificate": true,
42+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
45+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48+
"@aws-cdk/aws-redshift:columnId": true,
49+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
50+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
51+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
52+
"@aws-cdk/aws-kms:aliasNameRef": true,
53+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
54+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
55+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
56+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
57+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
58+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
59+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
60+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
61+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
62+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true
63+
}
64+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};

0 commit comments

Comments
 (0)