Wiki source code of Deployment Using CDK Code

Version 4.16 by Sanchita Singh on 2021/08/27

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc start="1" depth="6" numbered="false" scope="page"/}}
3 {{/box}}
4
5 {{warning}}
6 Installation on AWS is currently an XWiki Contrib project and not supported by the core XWiki Dev Team.
7 {{/warning}}
8
9 = Overview =
10
11 Another method you can use to deploy XWiki in your AWS account is by using the CDK code. AWS CDK or Cloud Development Kit is used in order to provision resources inside an AWS Account without the hassle of creating them manually and helps to lock down on configurations required for provisioning those resources so as to maintain consistency across various stages and installs. With CDK we can write infrastructure as code in languages like typescript, python, java, .NET. If you prefer to install your XWiki instance in a couple of clicks from the console we recommend you to [[use the Cloudformation Template>>Documentation.AdminGuide.Installation.XWiki Installation on AWS.Deployment Using Cloudformation Template.WebHome]]. But if you are a fan of AWS CLI and/or want to tweak the configuration according to your needs you can use the CDK code. You'll need basic programming knowledge if you want to tweak configuration according to you. But you can do it in CDK code in a much easier way as compared to cloudFormation template.
12
13 = Deployment Options =
14
15 Here, we provide two different types of installation: one demo/test installation and another one for a production installation. Demo installation Provides a built-in XWiki, with a portable database (HSQLDB) and a lightweight Java container (Jetty). This standalone distribution is not recommended in a production environment. If you need to use it on a production basis, you may look at the other option. With that there is an obvious choice of version of XWiki, we recommend these two options though you can install a specific version of your choice.
16
17 * Long-term support: This version is the latest stable version from the last XWiki cycle. This is the most stable version and is recommended to use in production.
18 * Stable: This version is the latest stable version from the current XWiki cycle. This is the version recommended if you wish to try out the new features from the cycle.
19
20 = Pre-Requisites =
21
22 * You must have the [[AWS CDK Command Line Interface (CLI) installed and configured>>https://docs.aws.amazon.com/de_de/cdk/latest/guide/getting_started.html]] or use a docker image.
23 * You should be using a root account or at least an IAM user with root privileges. Otherwise, you might get errors regarding permissions to create resources.
24 * You must have [[NPM installed>>https://docs.npmjs.com/downloading-and-installing-node-js-and-npm]] or use a docker image.
25
26 = Demo Installation =
27
28 == What You Will Build ==
29
30 Here, you will have an EC2 instance and inside it a built-in XWiki, with a portable database (HSQLDB) and a lightweight Java container (Jetty). You need to simply SSH into the EC2 instance and start XWiki. Follow the step-by-step instruction to do so.
31
32 {{warning}}
33 This installation is not to use in production. This is only for Demo purposes
34 {{/warning}}
35
36 == Deploying Demo XWiki ==
37
38 * First step would be to [[make a key in AWS console with name (% style="font-family:monospace" %)'(%%)xwiki-demo-key(% style="font-family:monospace" %)'>>https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#having-ec2-create-your-key-pair]](%%). Make sure to keep the name of your key-pair (% style="font-family:monospace" %)'xwiki-demo-key'(%%).
39 * Clone the repo https://github.com/xwiki-contrib/aws(((
40 {{code language="bash"}}
41 git clone https://github.com/xwiki-contrib/aws.git
42 {{/code}}
43 )))
44 * Navigate into the cloned directory(((
45 {{code language="bash"}}
46 cd aws
47 {{/code}}
48 )))
49 * Navigate into the Demo directory(((
50 {{code language="bash"}}
51 cd xwiki-demo-cdk
52 {{/code}}
53 )))
54 * Install all needed packages locally(((
55 {{code language="bash"}}
56 npm install
57 {{/code}}
58
59 or with docker:
60
61 {{code language="bash"}}
62 docker run -v "$PWD":/usr/src/app -w /usr/src/app node npm install
63 {{/code}}
64 )))
65 * Execute the deployment, and wait for the process to get complete.(((
66 {{code language="bash"}}
67 cdk deploy
68 {{/code}}
69 )))
70 * You have an EC2 instance with XWiki demo installed. Now to start the server, SSH into the newly created instance
71 and start XWiki.
72 * For starting XWiki, go into the folder(((
73 {{code language="bash"}}
74 cd xwikihome && cd xwiki-platform-distribution-flavor-jetty-hsqldb-13.1
75 {{/code}}
76 )))
77 * run ##start_xwiki.sh##(((
78 {{code language="bash"}}
79 chmod +x ./start_xwiki.sh && ./start_xwiki.sh
80 {{/code}}
81 )))
82 * Now, to connect to XWiki you need to go to port 8080 of public IP address.
83
84 = Production Installation =
85
86 == What You Will Build ==
87
88 Using this Clodformation template you'll be provisioning these resources in your AWS account.
89
90 * A virtual private cloud (VPC) that is configured across two Availability Zones. For each Availability Zone, this template provisions one public subnet and one private subnet, according to AWS best practices.
91 * In the public subnets, managed network address translation (NAT) gateways to provide outbound internet connectivity for instances in the private subnets.
92 * In the private subnets, Amazon Elastic File System(EFS), which provides simple, scalable file storage for XWiki files, Amazon Aurora database instances running MySQL and Elastic Container Service(ECS) fargate service.
93 * An AWS Loadbalancer, which you will connect to using the DNS provided at the end of the installation.
94 * An AWS Identity and Access Management (IAM) role to enable AWS resources created through the Template to access other AWS resources when required.
95
96 The production installation will create the following resources in your AWS account.
97
98 == Configuration parts within CDK in more details ==
99
100 Here we will have a look at some parts of the code and how you can configure it if you want according to your needs
101
102 * Inside the lib folder, we have the ##config.ts## file. There you will have two basic required configurations. First, one being the region you want to deploy your resources into and the second is the version of XWiki you want to choose. You can edit this file according to your needs. We recommend you to use ##xwiki:stable-mysql-tomcat## or ##xwiki:lts-mysql-tomcat## to set for ##xwikiversion##. Though you can choose [[any other ##mysql-tomcat## version from Docker Hub>>https://hub.docker.com/_/xwikitab=tags&page=1&ordering=last_updated&name=mysql-tomcat]] for the tag to be used for your preferred version.(((
103 {{code language="TypeScript"}}
104 export const region = 'us-east-1'; // region in which you want to configure xwiki instance
105 export const xwikiVersion = 'xwiki:mysql-tomcat' //or 'xwiki:mysql-stable-tomcat'
106 {{/code}}
107 )))
108 * Inside the ##lib/stacksvpc.ts## you have the IAAC that will provision a new VPC in your account. Here we used ##cidr##: ##10.42.42.0/24## which is small but sufficient for this installation. You can increase this if you wish to deploy other services inside this network in future.(((
109 {{code language="TypeScript"}}
110 public readonly xwikivpc: Vpc;
111 constructor (scope: cdk.App, id: string, props?: cdk.StackProps) {
112 super(scope, id, props)
113 this.xwikivpc = new Vpc(this, 'xwiki-vpc', {
114 cidr: '10.42.42.0/24',
115 defaultInstanceTenancy: DefaultInstanceTenancy.DEFAULT,
116 maxAzs: 2,
117 natGatewayProvider: NatProvider.gateway(),
118 natGateways: 1,
119 subnetConfiguration: [
120 {
121 name: 'public',
122 subnetType: SubnetType.PUBLIC,
123 cidrMask: 27
124 },
125 {
126 name: 'private-database',
127 subnetType: SubnetType.PRIVATE,
128 cidrMask: 26
129 }
130 ]
131 })
132 }
133 {{/code}}
134 )))
135 * We have configured two encryption keys to be used for storing resources passwords etc. We have enabled rotation by default, as suggested to be the best practice according to AWS documentation. AWS KMS rotates the key automatically every year. You don't need to remember or schedule the update.(((
136 {{code}}
137 const xwikiEncryptionKey = new Key(this, 'XWikiEncryptionKey', { //encryption key to be used by the file system and rds
138 alias: `xwiki`,
139 description: `Encryption Key for XWiki Storage Resources`,
140 enableKeyRotation: true,
141 enabled: true,
142 trustAccountIdentities: true,
143 });
144 const xwikiSecretEncryptionKey = new Key(this, 'XWikiSecretEncryptionKey', { //used for fenerating password for rds
145 alias: `xwiki-secret`,
146 description: `Encryption Key for XWiki Secrets`,
147 enableKeyRotation: true,
148 enabled: true,
149 trustAccountIdentities: true,
150 });
151 {{/code}}
152 )))
153 * We have configured two encrytion keys to be used for storing resources passowrd etc. We have enabled rotation by default and uses the key that we configured earlier(((
154 {{code}}
155 const xwikiEfs = new FileSystem(this, 'XWikiFileSystem', { // File System that will conatin static xwiki files
156 vpc: props.vpc,
157 enableAutomaticBackups: true,
158 encrypted: true,
159 kmsKey: xwikiEncryptionKey,
160 performanceMode: PerformanceMode.GENERAL_PURPOSE,
161 securityGroup: xwikiEfsSg,
162 vpcSubnets: props.vpc.selectSubnets(
163 {
164 subnetType: SubnetType.PRIVATE
165 }
166 )
167 });
168 {{/code}}
169 )))
170
171 This is not the whole configuration but only a part to give you an idea about code style and how to modify it according to your needs. You can get the whole code in the [[Github repository>>https://github.com/xwiki-contrib/aws]].
172
173 == Deploying Production XWiki ==
174
175 After installing and configuring the AWS Command Line Interface (CLI) with an access key and secret access key belonging to your root account or IAM user with root privileges, follow these steps to get your XWiki deployed.
176
177 * Clone the repo https://github.com/xwiki-contrib/aws(((
178 {{code language="bash"}}
179 git clone https://github.com/xwiki-contrib/aws.git
180 {{/code}}
181 )))
182 * Navigate into the clone Directory(((
183 {{code language="bash"}}
184 cd aws
185 {{/code}}
186 )))
187 * Navigate into the Production Directory(((
188 {{code language="bash"}}
189 cd xwiki-production-cdk
190 {{/code}}
191 )))
192 * Install all needed packages locally(((
193 {{code language="bash"}}
194 npm install
195 {{/code}}
196 )))
197 * Execute the deployment, and wait for the process to get complete.(((
198 {{code language="bash"}}
199 cdk deploy --all
200 {{/code}}
201 )))
202
203 {{warning}}
204 The stacks will be deployed in the region set in the ##config.ts## file in lib folder. The default set region is ##us-east-1##.
205 {{/warning}}
206
207 {{info}}
208 **TIP:** Consider choosing a region closest to your data center or corporate network to reduce network latency between systems running on AWS and the systems and users on your corporate network.
209 {{/info}}
210
211 * Monitor the status of creation of stacks in your command line and answer yes to the prompt questions asking permission to deploy. You will see this at the end of deployment of stacks.(((
212 {{image reference="cdk-output-aws.png"/}}
213 )))
214 * Connect to the LoadBalancer DNS shown in the output of the previous command to configure your newly hosted XWiki installation(((
215 {{image reference="xwiki-installed-output.png"/}}
216 )))
217
218 = Github Repository =
219
220 You can visit the [[GitHub repository>>https://github.com/xwiki-contrib/aws]] to download the CDK code for this deployment to modify it for your needs and to post your comments,
221
222 = Troubleshooting =
223
224 * You might get an ‘ResourceLimitExceeded’ error while deploying the stack. You get this error when ther resource you are trying to create already reached it quota limit. But you can request to increase quota in your AWS account. It can take a few days for the new service quota to become effective. For more details on how to request quota increase, refer to, https://aws.amazon.com/premiumsupport/knowledge-center/resourcelimitexceeded-sagemaker/
225 * If you get an “Unrecognised Resources” error you are creating the stack in a region where not all the resources needed are available. To solve this change the region to some other nearest region to your center.

Get Connected