Skip to content

Instantly share code, notes, and snippets.

@peterjgrainger
Created February 27, 2023 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjgrainger/adef4103ee19e9c2aa5d386185115c92 to your computer and use it in GitHub Desktop.
Save peterjgrainger/adef4103ee19e9c2aa5d386185115c92 to your computer and use it in GitHub Desktop.
auto-remediate-wrong-availability-zone
Parameters:
instanceType:
Description: Instance type
Type: String
Default: r6i.xlarge
availabilityZone:
Description: Availability Zone
Type: String
Default: us-east-1i
vpcId:
Description: VPC ID
Type: String
Default: <insert-default>
Resources:
myEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0a313d6098716f372
InstanceType: !Ref instanceType
Monitoring: true
AvailabilityZone: !Ref availabilityZone
SecurityGroupIds:
- !Ref secGroupName
UserData: !Base64 |
#!/bin/bash -ex
# put your script here
Tags:
- Key: key
Value: value
secGroupName:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: sg1
GroupDescription: sg1
VpcId: !Ref vpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 0
ToPort: 65535
CidrIp: 0.0.0.0/0
@peterjgrainger
Copy link
Author

Update the default VPC ID
aws cloudformation create-stack --stack-name myteststack --template-body file://create-instance.yaml --disable-rollback --region us-east-1
aws cloudformation wait stack-create-complete --stack-name myteststack --region us-east-1
aws cloudformation update-stack --stack-name myteststack --template-body file://create-instance.yaml --region us-east-1 --disable-rollback --parameters ParameterKey=availabilityZone,ParameterValue=us-east-1a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment