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(DataSync): Deploy DataSync agent on Amazon EC2 L2 construct #28701

Open
1 of 2 tasks
annguyen36 opened this issue Jan 13, 2024 · 9 comments
Open
1 of 2 tasks

feat(DataSync): Deploy DataSync agent on Amazon EC2 L2 construct #28701

annguyen36 opened this issue Jan 13, 2024 · 9 comments
Labels
@aws-cdk/aws-datasync feature-request A feature should be added or improved. p3

Comments

@annguyen36
Copy link

annguyen36 commented Jan 13, 2024

Describe the feature

It would be nice to have some L2 constructs for DataSync. Specially for creating the DataSync agent on EC2 instance.

Use Case

Currently only have L1 construct to create DataSync agent which requires the Activation Key. The situation is when the Agent is deployed in the EC2 instance which is part of the CDK deployment, we will need to make the HTTP request to get the ActivationKey, then use it to create the DataSync Agent.

Proposed Solution

Currently the solution is using custom resource to make this possible in a single CDK deployment. Specifically the Lambda function will make the HTTP call to get the Activation Key and send back to CloudFormation to continue create DataSync Agent resource.
This will be nice to have this abstract in the L2 construct.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.118

Environment details (OS name and version, etc.)

MacOs

@annguyen36 annguyen36 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 13, 2024
@annguyen36
Copy link
Author

waiting for triage before working on PR

@michaelciccarelli
Copy link

I understand that this can be addressed by writing a lambda but I think the point is to allow cdk to have this functionality natively via cdk.. this would be much easier, quicker to release multiple agents across several AWS accounts. For example, we want to deploy agents across dev, test and production for separation of data and not having this functionality built into CDK makes the deployments much more difficult. MIssing piece is just being able to natively retrieve the agent registration key.

@pahud
Copy link
Contributor

pahud commented Jan 16, 2024

@annguyen36 Before you start the PR draft, can you share a little bit about how would you implement the solution? I am not sure if this is a good idea to add this support in aws-ec2 modules. Can you share some high level abstraction and code samples?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 16, 2024
@annguyen36 annguyen36 changed the title fear(DataSync): Deploy DataSync agent on Amazon EC2 L2 construct featDataSync): Deploy DataSync agent on Amazon EC2 L2 construct Jan 16, 2024
@annguyen36 annguyen36 changed the title featDataSync): Deploy DataSync agent on Amazon EC2 L2 construct feat(DataSync): Deploy DataSync agent on Amazon EC2 L2 construct Jan 16, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 18, 2024
@annguyen36
Copy link
Author

annguyen36 commented Jan 18, 2024

Hi @pahud, I believe this should fall under the datasync module instead of ec2. So, basically to create the DataSync CfnAgent we will need the activation key. In the case that the agent is deployed in ec2 instance, there are couple ways to get the activation key (via console, ssh to the instance, or using cli). We can encapsulate this process using custom resource to make the http request. So my idea is to have the L2 construct to create EC2DataSyncAgent which contain:

  • the ec2 instance using the datasync ami
  • A lambda function and custom resource which used to make the http request
  • and use the Activation key to create CfnAgent.

Constructs idea:

    instance = ec2.Instance(self, "Instance",
            vpc=vpc,
            instance_type=ec2.InstanceType("t2.micro"),
            machine_image=ec2.MachineImage.from_ssm_parameter('/aws/service/datasync/ami'),
            security_group=sg,
            key_name="us-west-2",
        )
        
        on_event = lambda_.Function(self, "Function",
            runtime=lambda_.Runtime.NODEJS_18_X,
            handler="index.handler",
            code=lambda_.Code.from_asset('lambda'),
            timeout=Duration.seconds(300) 
        )
        get_activation_key = CustomResource(
            self, "GetActivationKey",
            # service_token=my_provider.service_token,
            service_token=on_event.function_arn,
            properties={
                "agentIpAddress": instance.instance_public_ip, < this will depend if agent using vpc endpoint
            }
        )
        # Create DataSync agent
        datasync.CfnAgent(self, "DataSyncAgent",
            activation_key=get_activation_key.get_att("ActivationKey").to_string(),
            agent_name="DataSyncAgent"
        )

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 18, 2024
@pahud
Copy link
Contributor

pahud commented Jan 24, 2024

I feel we probably should create an Agent L2 construct that auto generates the activation key under the hood if undefined. For example

new dataSync.Agent(this, 'Agent', {
  activationKey: dataSync.ActivationKey.fromEc2Instance(instance)
});

But this needs some discussion with the core team maintainer.

@amouly
Copy link

amouly commented Apr 5, 2024

Hi @pahud, I believe this should fall under the datasync module instead of ec2. So, basically to create the DataSync CfnAgent we will need the activation key. In the case that the agent is deployed in ec2 instance, there are couple ways to get the activation key (via console, ssh to the instance, or using cli). We can encapsulate this process using custom resource to make the http request. So my idea is to have the L2 construct to create EC2DataSyncAgent which contain:

  • the ec2 instance using the datasync ami
  • A lambda function and custom resource which used to make the http request
  • and use the Activation key to create CfnAgent.

Constructs idea:

    instance = ec2.Instance(self, "Instance",
            vpc=vpc,
            instance_type=ec2.InstanceType("t2.micro"),
            machine_image=ec2.MachineImage.from_ssm_parameter('/aws/service/datasync/ami'),
            security_group=sg,
            key_name="us-west-2",
        )
        
        on_event = lambda_.Function(self, "Function",
            runtime=lambda_.Runtime.NODEJS_18_X,
            handler="index.handler",
            code=lambda_.Code.from_asset('lambda'),
            timeout=Duration.seconds(300) 
        )
        get_activation_key = CustomResource(
            self, "GetActivationKey",
            # service_token=my_provider.service_token,
            service_token=on_event.function_arn,
            properties={
                "agentIpAddress": instance.instance_public_ip, < this will depend if agent using vpc endpoint
            }
        )
        # Create DataSync agent
        datasync.CfnAgent(self, "DataSyncAgent",
            activation_key=get_activation_key.get_att("ActivationKey").to_string(),
            agent_name="DataSyncAgent"
        )

I would like to implement this solution on my end, due I need to implement DataSync for GCS->S3 on my side.

Do you have a repository or something with this solution?

@pahud pahud added p3 and removed p2 labels Jun 11, 2024
@matt-challe
Copy link

Is there an accepted interim solution to this issue while a more permanent solution is being worked on?

@zentavr
Copy link

zentavr commented Dec 20, 2024

@amouly trying to develop that Lambda and I'm in stuck with it's logic. Every time I make a request to HTTP endpoint of Datasync Agent - I receive the different key.

Also I'd read somewhere that as soon as agent registers itself - it closes the HTTP endpoint, so Lambda will fail.

Should we keep that key somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-datasync feature-request A feature should be added or improved. p3
Projects
None yet
Development

No branches or pull requests

6 participants