Skip to content

Commit 75e0cb4

Browse files
committed
Update user data to new API
1 parent 8f7baa8 commit 75e0cb4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

dotcom-rendering/cdk/lib/userData.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UserData } from 'aws-cdk-lib/aws-ec2';
12
import type { RenderingCDKStackProps } from './renderingStack';
23

34
interface UserDataProps extends Pick<RenderingCDKStackProps, 'stage'> {
@@ -15,25 +16,23 @@ export const getUserData = ({
1516
guStack,
1617
stage,
1718
artifactsBucket,
18-
}: UserDataProps): string => {
19-
const userData = [
19+
}: UserDataProps): UserData => {
20+
const userData = UserData.forLinux();
21+
// create groups, download artifact, unzip and set permissions
22+
userData.addCommands(
2023
`#!/bin/bash -ev`,
21-
2224
`groupadd frontend`,
2325
`useradd -r -m -s /usr/bin/nologin -g frontend dotcom-rendering`,
2426
`cd /home/dotcom-rendering`,
25-
2627
`aws --region eu-west-1 s3 cp s3://${artifactsBucket}/frontend/${stage}/${guApp}/${guApp}.tar.gz ./`,
2728
`tar -zxf ${guApp}.tar.gz ${guApp}`,
28-
2929
`chown -R dotcom-rendering:frontend ${guApp}`,
30-
3130
`cd ${guApp}`,
32-
3331
`mkdir /var/log/dotcom-rendering`,
3432
`chown -R dotcom-rendering:frontend /var/log/dotcom-rendering`,
35-
36-
// write out systemd file
33+
);
34+
// write out systemd service file
35+
userData.addCommands(
3736
`cat > /etc/systemd/system/${guApp}.service << EOF`,
3837
`[Unit]`,
3938
`Description=${guApp}`,
@@ -55,10 +54,11 @@ export const getUserData = ({
5554
`[Install]`,
5655
`WantedBy=multi-user.target`,
5756
`EOF`,
58-
57+
);
58+
// enable and start the service
59+
userData.addCommands(
5960
`systemctl enable ${guApp}`, // enable the service
6061
`systemctl start ${guApp}`, // start the service
61-
].join('\n');
62-
62+
);
6363
return userData;
6464
};

0 commit comments

Comments
 (0)