By using AWS re:Post, you agree to the Terms of Use

Questions tagged with Infrastructure as Code

Sort by most recent
  • 1
  • 2
  • 12 / page

Browse through the questions and answers listed below or filter and sort to narrow down your results.

In CDK, how do you enable `associatePublicIpAddress` in an AutoScalingGroup that has a `mixedInstancesPolicy`?

I'm using AWS CDK and am trying to enable the associatePublicIpAddress property for an AutoScalingGroup that's using a launch template. My first attempt was to just set `associatePublicIpAddress: true`, but I get this error (https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts#L1526-L1528) ```typescript // first attempt new asg.AutoScalingGroup(this, 'ASG', { associatePublicIpAddress: true, // here minCapacity: 1, maxCapacity: 1, vpc, vpcSubnets: { subnetType: SubnetType.PUBLIC, onePerAz: true, availabilityZones: [availabilityZone], }, mixedInstancesPolicy: { instancesDistribution: { spotMaxPrice: '1.00', onDemandPercentageAboveBaseCapacity: 0, }, launchTemplate: new LaunchTemplate(this, 'LaunchTemplate', { securityGroup: this._securityGroup, role, instanceType machineImage, userData: UserData.forLinux(), }), launchTemplateOverrides: [ { instanceType: InstanceType.of( InstanceClass.T4G, InstanceSize.NANO ), }, ], }, keyName, }) ``` ```typescript // I hit this error from the CDK if (props.associatePublicIpAddress) { throw new Error('Setting \'associatePublicIpAddress\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set'); } ``` My second attempt was to not set `associatePublicIpAddress` and see if it gets set automatically because the AutoScalingGroup is in a public availablity zone with an internet gateway. However, it still doesn't provision a public ip address. Has anyone been able to create an autoscaling group with a mix instance policy and an associated public ip?
1
answers
0
votes
49
views
asked 3 months ago

"NameError: name 'self' is not defined" in CDK with python

I'm just using the sample code from: https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_healthlake/CfnFHIRDatastore.html#aws_cdk.aws_healthlake.CfnFHIRDatastore.add_deletion_override And I'm adding the import statements not included in that example. ``` #!/usr/bin/env python3 import aws_cdk as cdk import aws_cdk.aws_healthlake as healthlake from constructs import Construct from healthlake.healthlake_stack import HealthlakeStack app = cdk.App() class HealthlakeStack(): def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) cfn_fHIRDatastore = healthlake.CfnFHIRDatastore(self, "MyCfnFHIRDatastore", datastore_type_version="R4" ) HealthlakeStack(app, "HealthLake") app.synth() ``` When I run `cdk synth` on this, I get back: ``` Traceback (most recent call last): File "app.py", line 13, in <module> class HealthlakeStack(): File "app.py", line 17, in HealthlakeStack cfn_fHIRDatastore = healthlake.CfnFHIRDatastore(self, "MyCfnFHIRDatastore", NameError: name 'self' is not defined ``` And if I remove `self`, I get: ``` Traceback (most recent call last): File "app.py", line 11, in <module> class HealthlakeStack(): File "app.py", line 15, in HealthlakeStack cfn_fHIRDatastore = healthlake.CfnFHIRDatastore("MyCfnFHIRDatastore", File "redacted/python/site-packages/jsii/_runtime.py", line 86, in __call__ inst = super().__call__(*args, **kwargs) TypeError: __init__() missing 1 required positional argument: 'id' ``` And I tried a few other things. I'm guessing I'm just not nesting this correctly or something else basic to Python.
1
answers
0
votes
64
views
asked 3 months ago
  • 1
  • 2
  • 12 / page