(ec2): import an existing AutoScalingGroup with a Role
See original GitHub issueI’m trying to referring an existing AutoScalingGroup from my CodeDeploy with AutoScalingGroup.from_auto_scaling_group_name static method in order to integrate with CodePipeline for automating EC2/On-premise deployment. However, the Role from AutoScalingGroup is not being imported.
Reproduction Steps
-
Refer existing AutoScaling Group:
asg_1 = autoscaling.AutoScalingGroup.from_auto_scaling_group_name(self, "AutoScaleGroup", "WSAutoscaleStack-webServerAsgIdASG12345-XXXXXX")
-
EC2 Deployment Groups:
deployment_group = codedeploy.ServerDeploymentGroup(self, "CodeDeployDeploymentGroup", deployment_group_name="MyDeploymentGroup", install_agent=True, auto_scaling_groups=[asg_1])
What did you expect to happen?
Ideally, the referenced resource should be imported as an object, so that I can use it all dependents including iam.role from the resource. (c.f. from CodeDeploy Application Environment configuration, choose the Amazon EC2 Auto Scaling group where the current application revision is deployed)
What actually happened?
The error that I’m getting is as follows:
jsii.errors.JSIIError: Cannot get policy fragment of AMIPipelineStack/AutoScaleGroup, resource imported without a role
Environment
- CDK CLI Version : 1.94.0 (build 2c1c0eb)
- Framework Version:
- Node.js Version: v15.11.0
- OS : macOS Catalina
- Language (Version): Python (3.8.7)
Other
This issue was posted and confirmed. The issue is linked, https://stackoverflow.com/questions/66748035/refer-import-existing-autoscalinggroup-resource-from-cdk-stack
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top GitHub Comments
@peterwoodworth I believe what we need here is a new method
fromAutoScalingGroupAttributes()
inAutoScalingGroup
that allows you to specify the Role of the ASG. I’ve converted this to a feature request.@joon73 if you’d consider implementing this functionality, it should be pretty easy. Take a look at our “Contributing guide” to get started: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md.
Thanks, Adam
How can we leverage Boto3 to address the problem? Example below: import boto3 cloudformation = boto3.resource(‘cloudformation’) #get the logical ID of resource created from STACK-A stack_resource = cloudformation.StackResource('STACK-A,‘logical_id’) #Typecast this as per the Resource and use that in STACK-B