sebranchett / ec2-instance-python

AWS CDK Python example of an EC2 that can be accessed by AWS System Manager and has access to S3 bucket. Configuration shell script can be provided to run on creation
Apache License 2.0
0 stars 1 forks source link

Use 'parameters' for ami, ec2 type, name of bucket #3

Closed sebranchett closed 2 years ago

sebranchett commented 2 years ago

Typed this in while trying to follow Nathan (Sentia): construct in stack, extend stack class, init add my args or cfn parameters of commbinatie

voor **kwars in def init instance_type: str

instance_type = cfnParameter(self, 'instanchet_type_parameter', defualt- instance_type) instance_type = ec2.InstanceType(instance_type_param.value_as_string)

user_data = ec2.UserData.for_linux() user_data.add_commands(""" script """)

sebranchett commented 2 years ago

Extended the stack class with instance_type, ami_name, ami_owner, bucket_name. Defined the instance_type and the bucket_name as a CloudFormation parameter. Did NOT do the same to the ami_name and ami_owner as these are used to look up the AMI. Looking up with parameters gives errors about TOKENs. You try to use the parameter values, before they can be resolved.

This could be fixed, maybe, by defining an image directly with the AMI ID (and region and account?), but this is error prone and not easy to understand.

Decided not to travel this path.

If someone wants to use the CF template with a different AMI, they can edit "ImageId" in the template before deploying. The "ImageId" has to be available in the region used.