How to attach an EBS volume to Cloud9 via CDK stack?

2

I am creating a cloud9 environment from CDK as below. I want to attach/adjust EBS volume size and attach a IAM Role to the EC2 of the cloud9 from the CDK stack. Can anyone help?

import { aws_cloud9, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class Cloud9CdkStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    // cloud9 environment 
    const cloud9 = new aws_cloud9.CfnEnvironmentEC2(
      this,
      'CdkCloud9Example',
      {
        automaticStopTimeMinutes: 30,
        instanceType: 't2.large',
        name: 'CdkCloud9Example',
        connectionType: 'CONNECT_SSM',
        ownerArn: 'arn:aws:iam::IAM_USER_ID:user/IAM_USER_NAME'
      }
    )

    // access the ec2 and attach volume ??

  }
}

  • I also hope to have a tutorial about how to reduce the size of root EBS for windows instances also.

hai
已提問 2 年前檢視次數 867 次
1 個回答
0
已接受的答案

There is no CDK API to do this directly. However, you can use one of the following approaches to implement it by yourself.

A Lambda-backed custom CDK resource in your CDK stack

Implement a custom resource using this example as a reference. In the Lambda function, you can modify the underlying EC2 instance by using the AWS SDK. The EC2 instance running a Cloud9 environment has a tag aws:cloud9:environment with the value of the environment ID, so you can use this tag to obtain the EC2 instance ID. Using the Lambda function and the AWS SDK, you can modify the underlying EC2 instance in the way you want.

Systems Manager Document

You can leverage AWS Systems Manager and its Documents for setting up the instance. Take a look on this CDK construct on ConstructHub. This construct provides a method resizeEBSTo for configuring the instance's EBS volume. You can add another Document steps using the addDocumentSteps method for any other required changes.

profile pictureAWS
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南