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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠