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 年前866 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则