aws

NS International move to Aws

The term lift and shift was thrown out the window and we’ve build a fully automated instructure build pipeline to facilitate the apps. From old jboss to modern docker based apps. NS International, formerly NS Hispeed, is the rail operator in the Netherlands that operates international intercity and high-speed train connections with Belgium, France, Germany and Switzerland. NS International is part of the Dutch Railways. It currently operates both direct and indirect services.

Display AWS Cloudformation logs in pipelines

Using cloudformation is great, it gives you insane super powers but there are some small things that annoy me when using it in pipelines. My biggest issue is that it is not displaying the steps it takes in kind of real time’ish to stdout, so that’s where the following snippet will help. The code What the output looks like [ { "StackId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324", "EventId": "5816a850-3333-11ea-83e6-02bbe9b74d60", "StackName": "tech-blog", "LogicalResourceId": "tech-blog", "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324", "ResourceType": "AWS::CloudFormation::Stack", "Timestamp": "2020-01-09T22:57:00.

Mass delete cloudformation stacks

The oneliner: # This will delete all stacks in the account connected to yourprofile with the string "delete-me" in the stackname for StackName in $(aws --profile yourprofile cloudformation list-stacks --query 'StackSummaries[?contains(StackName, `delete-me`) == `true`] .StackName' --output text); do echo $StackName ; aws --profile yourprofile cloudformation delete-stack --stack-name $StackName ; done

Cloudformation & Autoscaling

In this session we'll take a look at Cloudformation the Infra As Code language for AWS and how to use it to build endlessly scalable infrastructure and make sure your stack can handle anything.

Get ec2 arn for local ec2 machine with python

A super minimal urllib based arn constructor based on local metadata import urllib.request # local ec2 arn: f = urllib.request.urlopen('http://169.254.169.254/latest/meta-data/placement/availability-zone') az = f.read().decode('utf-8') f = urllib.request.urlopen('http://169.254.169.254/latest/meta-data/instance-id') instance = f.read().decode('utf-8') arn = 'arn:aws:ec2:' + az + ':instance/' + instance print(arn) This returns arn as used by the EC2 Spot Instance Interruption Warning event { "version": "0", "id": "03a51c99-95cb-c6e8-03a8-3ce3ac402d64", "detail-type": "EC2 Spot Instance Interruption Warning", "source": "aws.ec2", "account": "763603311319", "time": "2018-09-16T13:17:10Z", "region": "eu-west-1", "resources": [ "arn:aws:ec2:eu-west-1b:instance/i-05493b58ebcba0c43" ], "detail": { "instance-id": "i-05493b58ebcba0c43", "instance-action": "terminate" } }

aws cli search for latest ami

This simple oneliner gets you the latest ami in a given region for a specific search term. # get the latest ecs-optimized amazon ami in eu-west-1 aws ec2 describe-images --region eu-west-1 --owners amazon --filters "Name=name,Values=*amazon-ecs-optimized" "Name=architecture,Values=x86_64" "Name=architecture,Values=x86_64" --query 'sort_by(Images, &CreationDate)[-1].ImageId' So lets break it down to give you what you need to get your favorite ami. # Get the full ami list for name search term "*amazon-ecs-optimized" aws ec2 describe-images --region eu-west-1 --owners amazon --filters "Name=name,Values=*amazon-ecs-optimized" "Name=architecture,Values=x86_64" # this is searching for just the name, you could of course replace or expand this with other atributes like: aws ec2 describe-images --region eu-west-1 --owners amazon --filters "Name=name,Values=*amazon-ecs-optimized" "Name=architecture,Values=x86_64" "Name=block-device-mapping.