question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(ec2): import an existing AutoScalingGroup with a Role

See original GitHub issue

I’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:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
skinny85commented, Jul 1, 2021

@peterwoodworth I believe what we need here is a new method fromAutoScalingGroupAttributes() in AutoScalingGroup 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

0reactions
aloksinghGITcommented, Jan 21, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach EC2 instances to your Auto Scaling group
Use the following procedure to attach an instance to your Auto Scaling group. To attach an instance to an existing Auto Scaling group....
Read more >
Refer/Import existing AutoScalingGroup Resource from CDK ...
Looks like the fromAutoScalingGroupName method doesn't "Import" the role (see here). One option you have is to implement that import by ...
Read more >
Import an Existing ASG
In this procedure, you will import the configuration of an existing AWS Autoscaling Group (ASG) to Spot so that the ASG can be...
Read more >
How to deploy an ALB + ASG + EC2 using CDK and TypeScript
Creating the Auto Scaling Group ; import * ; import * ; import * ; import { CdkEc2Construct } from '../lib/cdk-ec2-construct.ts' ; cdk.Stack...
Read more >
Adding Extra Permissions to an IAM Role in EC2 AutoScaling
When importing the Platform9 IAM policy, the following permissions are required on your AWS account. ELB Management; Route 53 DNS Configuration ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found