Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
MatthewJDavis / params.json
Created June 5, 2017 21:03
AWS Cloudformation JSON parameters for EC2 instance
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Create a basic Amazon Linux Server",
"Parameters": {
"KeyName": {
"Description": "Key Pair name",
"Type": "AWS::EC2::KeyPair::KeyName",
"Default": "keyPair"
},
"VPC": {
@MatthewJDavis
MatthewJDavis / params.yaml
Created June 5, 2017 21:06
AWS cloudformation EC2 YAML parameters
AWSTemplateFormatVersion: 2010-09-09
Description: Create a basic Amazon Linux Server with security group in existing VPC and subnet
Parameters:
KeyName:
Description: Key Pair name
Type: 'AWS::EC2::KeyPair::KeyName'
Default: keyPair
VPC:
Description: Select a VPC
Type: 'AWS::EC2::VPC::Id'
@MatthewJDavis
MatthewJDavis / aws-server.yaml
Last active May 23, 2019 04:43
AWS cloudformation YAML template
AWSTemplateFormatVersion: 2010-09-09
Description: Create a basic Amazon Linux Server with security group in existing VPC and subnet
Parameters:
KeyName:
Description: Key Pair name
Type: 'AWS::EC2::KeyPair::KeyName'
Default: keyPair
VPC:
Description: Select a VPC
Type: 'AWS::EC2::VPC::Id'
@MatthewJDavis
MatthewJDavis / 2-instances-2-eips.yaml
Created June 6, 2017 19:56
2 EC2 Insances with Elastic IP addresses
AWSTemplateFormatVersion: 2010-09-09
Description: Create a basic Amazon Linux Server with security group in existing VPC and subnet
Parameters:
KeyName:
Description: Key Pair name
Type: 'AWS::EC2::KeyPair::KeyName'
Default: keyPair
VPC:
Description: Select a VPC
Type: 'AWS::EC2::VPC::Id'
@MatthewJDavis
MatthewJDavis / Get-AmazonLinuxAMIId.ps1
Created June 15, 2017 19:44
Get the lastest Amazon Linux AMI
#will return the latest Amazon Linux AMI IDs using EBS for the listed regions
$regions = "eu-west-1","eu-west-2","eu-central-1"
foreach($region in $regions){
$ami = Get-EC2Image -Region $region |
Where-Object {$_.imageowneralias -eq "amazon" -and $_.virtualizationtype -eq "hvm" -and $_.name -like "*amzn-ami-hvm*" -and $_.rootdevicetype -eq "ebs"} |
Sort-Object -Property creationdate -Descending |
Select-Object -Property imageid -First 1
$output = "$region = " + $ami.ImageId
@MatthewJDavis
MatthewJDavis / Update-MDEC2ImageAMIID.ps1
Last active July 17, 2017 20:28
update ami id in cloudformation
# Get latest Amazon Windows Core AMI and update the ami id in the specified file.
# Needs the AWSPowerShell module installed and credentials configured.
Import-Module -Name AWSPowerShell
$windowsName = 'WINDOWS_2016_Core'
$region = 'eu-west-2'
$cfFileLocation = 'c:\cloudfromation\win-servers\ec2.yml'
#Get the latest AMI ID
$imageId = (Get-EC2ImageByName -Name $windowsName -Region $region).ImageId
$majorVersion = $Host.Version.Major.ToString()
$minorVersion = $Host.Version.Minor.ToString()
$version = "$majorVersion.$minorVersion"
#module Imports
Import-Module azureext
Import-Module AWSPowerShell
#aliases
New-Alias -Name sub -Value Select-AzureRmSubscription
@MatthewJDavis
MatthewJDavis / new-domainservicesvnet.ps1
Created July 24, 2017 20:30
Creates resource group, vnet and subnets in Azure
$rgName = 'domain-services-rg'
$location = 'Northeurope'
$vnetName = 'northeurope-vnet'
$addressPrefix = '10.1.0.0/16'
$subName1 = 'gateway-sub'
$subAddress1 = '10.1.0.0/28'
$subName2 = 'frontend-sub'
$subAddress2 = '10.1.1.0/24'
$subName3 = 'backend-sub'
$subAddress3 = '10.1.2.0/24'
@MatthewJDavis
MatthewJDavis / classic-network-config.xml
Created July 24, 2017 20:49
Classic Azure vnet config
<?xml version="1.0" encoding="utf-8"?>
<NetworkConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
<VirtualNetworkConfiguration>
<Dns />
<VirtualNetworkSites>
<VirtualNetworkSite name="Group domain-services-rg domain-services-vnet" Location="North Europe">
<AddressSpace>
<AddressPrefix>10.0.0.0/16</AddressPrefix>
</AddressSpace>
<Subnets>
@MatthewJDavis
MatthewJDavis / New-DomainServicesPeering.ps1
Created July 25, 2017 19:11
Set up VNET peering between ARM and classic vnet
# Set up vnet perring between the classic and ARM vnet
$resourceGroupName = 'domain-services-rg'
$classicVnetName = 'domain-services-vnet'
# Enter the name of the AzureRM subscription the VNETs are deployed in. Run (Get-AzureRmSubscription).SubscriptionName after authenticating to AzureRM
$subScriptionName = ''
# save current vnet in var
$vnet = Get-AzureRmVirtualNetwork -Name northeurope-vnet -ResourceGroupName domain-services-rg
# create the id for the classic vnet - we need the subscription id, resource group name and classic vnet to form the id