Skip to main content

NPM version PyPI version release

cdk-keycloak

CDK construct library that allows you to create KeyCloak on AWS in TypeScript or Python

Note

This project has been migrated to CDK v2.

CDK v1 compatible version is deprecated now.

Sample

For Keycloak 17+ versions, please specify hostname for the Keycloak server.

import { KeyCloak } from 'cdk-keycloak';

const app = new cdk.App();

const env = {
  region: process.env.CDK_DEFAULT_REGION,
  account: process.env.CDK_DEFAULT_ACCOUNT,
};

const stack = new cdk.Stack(app, 'keycloak-demo', { env });
new KeyCloak(stack, 'KeyCloak', {
  hostname: 'keycloak.example.com',
  certificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/293cf875-ca98-4c2e-a797-e1cf6df2553c',
  keycloakVersion: KeycloakVersion.V22_0_4,
});

Keycloak version pinning

Use keycloakVersion to specify the version.

new KeyCloak(stack, 'KeyCloak', {
  hostname,
  certificateArn,
  keycloakVersion: KeycloakVersion.V22_0_4,
});

To specify any other verion not defined in the construct, use KeycloakVersion.of('x.x.x'). This allows you to specify any new version as soon as it's available. However, as new versions will not always be tested and validated with this construct library, make sure you fully backup and test before you use any new version in the production environment.

Aurora Serverless support

The KeyCloak construct provisions the Amaozn RDS cluster for MySQL with 2 database instances under the hood, to opt in Amazon Aurora Serverless, use auroraServerless to opt in Amazon Aurora Serverless cluster. Please note only some regions are supported, check Supported features in Amazon Aurora by AWS Region and Aurora DB engine for availability.

// Aurora Serverless v1
new KeyCloak(stack, 'KeyCloak', {
  hostname,
  certificateArn,
  keycloakVersion,
  auroraServerless: true,
});

// Aurora Serverless v2
new KeyCloak(stack, 'KeyCloak', {
  hostname,
  certificateArn,
  keycloakVersion,
  auroraServerlessV2: true,
});

Behind the scene, a default RDS cluster for MySQL with 2 database instances will be created.

Opt-in for Single RDS instance

To create single RDS instance for your testing or development environment, use singleDbInstance to turn on the single db instance deployment.

Plesae note this is not recommended for production environment.

new KeyCloak(stack, 'KeyCloak', {
  hostname,
  certificateArn,
  keycloakVersion,
  singleDbInstance: true,
});

Service Auto Scaling

Define autoScaleTask for the ecs service task autoscaling. For example:

new KeyCloak(stack, 'KeyCloak', {
  hostname,
  certificateArn,
  keycloakVersion,
  auroraServerlessV2: true,
  nodeCount: 2,
  autoScaleTask: {
    min: 2,
    max: 10,
    targetCpuUtilization: 60,
  },
});

Customize fargate task settings

Define taskCpu or taskMemory for overriding the defaults for the ecs service task. Could be useful for development environments. For example:

new KeyCloak(stack, 'KeyCloak', {
  hostname,
  certificateArn,
  keycloakVersion,
  nodeCount: 1,
  taskCpu: 512,
  taskMemory: 2048,
});

Deploy in existing Vpc Subnets

You can deploy the workload in the existing Vpc and subnets. The publicSubnets are for the ALB, privateSubnets for the keycloak container tasks and databaseSubnets for the database.

The best practice is to specify isolated subnets for databaseSubnets, however, in some cases might have no existing isolates subnets then the private subnets are also acceptable.

Consider the sample below:

new KeyCloak(stack, 'KeyCloak', {
  hostname: 'keycloak.example.com',
  keycloakVersion: KeycloakVersion.V22_0_4,
  certificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/293cf875-ca98-4c2e-a797-e1cf6df2553c',
  vpc: ec2.Vpc.fromLookup(stack, 'Vpc', { vpcId: 'vpc-0417e46d' }),
  publicSubnets: {
    subnets: [
      ec2.Subnet.fromSubnetId(stack, 'pub-1a', 'subnet-5bbe7b32'),
      ec2.Subnet.fromSubnetId(stack, 'pub-1b', 'subnet-0428367c'),
      ec2.Subnet.fromSubnetId(stack, 'pub-1c', 'subnet-1586a75f'),
    ],
  },
  privateSubnets: {
    subnets: [
      ec2.Subnet.fromSubnetId(stack, 'priv-1a', 'subnet-0e9460dbcfc4cf6ee'),
      ec2.Subnet.fromSubnetId(stack, 'priv-1b', 'subnet-0562f666bdf5c29af'),
      ec2.Subnet.fromSubnetId(stack, 'priv-1c', 'subnet-00ab15c0022872f06'),
    ],
  },
  databaseSubnets: {
    subnets: [
      ec2.Subnet.fromSubnetId(stack, 'db-1a', 'subnet-0e9460dbcfc4cf6ee'),
      ec2.Subnet.fromSubnetId(stack, 'db-1b', 'subnet-0562f666bdf5c29af'),
      ec2.Subnet.fromSubnetId(stack, 'db-1c', 'subnet-00ab15c0022872f06'),
    ],
  },
});

AWS China Regions

This library support AWS China regions cn-north-1 and cn-northwest-1 and will auto select local docker image mirror to accelerate the image pulling. You don't have to do anything.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Metadata

Release files for cdk-keycloak 2.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdk-keycloak 2.9.0
File Size Uploaded
cdk-keycloak-2.9.0.tar.gz 76.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cdk-keycloak 2.9.0
File Interpreter ABI Platform
cdk_keycloak-2.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 151.1 kB

Release files / cdk-keycloak-2.9.0.tar.gz

Download URL cdk-keycloak-2.9.0.tar.gz
Size 76.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0595d72bf3ebdad226852f75c8c282bbd4b64a15e6fc1d3e520d6741433243d6
BLAKE2b-256 checksum
How to use checksums
1aee2f25f3a745a9a5fe0af3d0e4c0b052eb459191035bbebb9c8387caec3e55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / cdk_keycloak-2.9.0-py3-none-any.whl

Download URL cdk_keycloak-2.9.0-py3-none-any.whl
Size 74.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b42677ed74c2b060ee8ab7cd3712c620602f5bef43a85082a78accd13d0788d
BLAKE2b-256 checksum
How to use checksums
95c13d889924b0ddc4092ebf0cf34b5fc0cf4efdf3410a1e8254d1da7891fd44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

2.9.0 This release

2 release files

2.8.1

2 release files

2.8.0

2 release files

2.7.1

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

0.2.46

2 release files

0.2.44

2 release files

0.2.43

2 release files

0.2.42

2 release files

0.2.40

2 release files

0.2.39

2 release files

0.2.38

2 release files

0.2.37

2 release files

0.2.32

2 release files

0.2.31

2 release files

0.2.30

2 release files

0.2.29

2 release files

0.2.28

2 release files

0.2.27

2 release files

0.2.26

2 release files

0.2.25

2 release files

0.2.24

2 release files

0.2.23

2 release files

0.2.22

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.14

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.50

2 release files

0.0.49

2 release files

0.0.48

2 release files

0.0.47

2 release files

0.0.46

2 release files

0.0.45

2 release files

0.0.44

2 release files

0.0.43

2 release files

0.0.42

2 release files

0.0.41

2 release files

0.0.40

2 release files

0.0.39

2 release files

0.0.38

2 release files

0.0.37

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page