Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloud9): support setting automaticStopTimeMinutes #25593

Merged
merged 12 commits into from
Jun 5, 2023
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-cloud9-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ new cloud9.Ec2Environment(this, 'C9Env', {
owner: cloud9.Owner.user(user)
})
```

## Auto-Hibernation

A Cloud9 environemnt can automatically start and stop the associated EC2 instance to reduce costs.

Use `automaticStopTimeMinutes` to specify the number of minutes until the running instance is shut down after the environment was last used.

```ts
const defaultVpc = ec2.Vpc.fromLookup(this, 'DefaultVPC', { isDefault: true });
new cloud9.Ec2Environment(this, 'Cloud9Env2', {
vpc: defaultVpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,
automaticStopTimeMinutes: 30,
});
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-cloud9-alpha/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ export interface Ec2EnvironmentProps {
*
*/
readonly imageId: ImageId

/**
* The number of minutes until the running instance is shut down after the
* environment was last used.
*
* Setting a value of 0 means the instance will never be automatically shut down."
*
* @default - The instance will not be shut down automatically.
*/
readonly automaticStopTimeMinutes?: number
ba032759 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -200,6 +210,7 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
})) : undefined,
connectionType: props.connectionType ?? ConnectionType.CONNECT_SSH,
imageId: props.imageId,
automaticStopTimeMinutes: props.automaticStopTimeMinutes,
});
this.environmentId = c9env.ref;
this.ec2EnvironmentArn = c9env.getAtt('Arn').toString();
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-cloud9-alpha/test/cloud9.environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ test('environment owner can be account root', () => {
});
});

test('can set automaticStopTimeMinutes', () => {
// WHEN
const automaticStopTimeMinutes = 30;
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,
automaticStopTimeMinutes,
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Cloud9::EnvironmentEC2', {
AutomaticStopTimeMinutes: automaticStopTimeMinutes,
});
});

test.each([
[ConnectionType.CONNECT_SSH, 'CONNECT_SSH'],
[ConnectionType.CONNECT_SSM, 'CONNECT_SSM'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "31.0.0",
"files": {
"b4ace33442eb5fb8a32765fb178c8b0cb78d32ae32217070deb47be21b72ce44": {
"source": {
"path": "C9AutomaticStopTimeMinutesStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "b4ace33442eb5fb8a32765fb178c8b0cb78d32ae32217070deb47be21b72ce44.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading