AWS SSM Documents

SSM

Simple Server management. This is a feature offered by AWS that allows you to send commands to your instances to update them or install software. This feature can be used in a variety of usecases. Updating already running instances, installing missing software, etc. I personally have used it in relation to creating custom AMIs that will bootstrap a certain base AMI and install whatever i want for my future AMIs. When the instance is installed i create a new AMI with updated features, updates, programs, settings etc.

Automation structures

The feature iv’e been looking mostly into is the automation document. This document is a JSON fil that describes how a certain flow will look like. When started, the document will automating each step in the flow.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
"description":"Systems Manager Automation Demo - Patch and Create a New AMI",
"schemaVersion":"0.3",
"assumeRole":"the role ARN you created",
"parameters":{
"sourceAMIid":{
"type":"String",
"description":"AMI to patch"
},
"targetAMIname":{
"type":"String",
"description":"Name of new AMI",
"default":"patchedAMI-{{global:DATE_TIME}}"
}
},
"mainSteps":[
{
"name":"startInstances",
"action":"aws:runInstances",
"timeoutSeconds":1200,
"maxAttempts":1,
"onFailure":"Abort",
"inputs":{
"ImageId":"{{ sourceAMIid }}",
"InstanceType":"m3.large",
"MinInstanceCount":1,
"MaxInstanceCount":1,
"IamInstanceProfileName":"the name of the IAM role you created"
}
},
{
"name":"installMissingWindowsUpdates",
"action":"aws:runCommand",
"maxAttempts":1,
"onFailure":"Continue",
"inputs":{
"DocumentName":"AWS-InstallMissingWindowsUpdates",
"InstanceIds":[
"{{ startInstances.InstanceIds }}"
],
"Parameters":{
"UpdateLevel":"Important"
}
}
},
{
"name":"stopInstance",
"action":"aws:changeInstanceState",
"maxAttempts":1,
"onFailure":"Continue",
"inputs":{
"InstanceIds":[
"{{ startInstances.InstanceIds }}"
],
"DesiredState":"stopped"
}
},
{
"name":"createImage",
"action":"aws:createImage",
"maxAttempts":1,
"onFailure":"Continue",
"inputs":{
"InstanceId":"{{ startInstances.InstanceIds }}",
"ImageName":"{{ targetAMIname }}",
"NoReboot":true,
"ImageDescription":"AMI created by EC2 Automation"
}
},
{
"name":"createTags",
"action":"aws:createTags",
"maxAttempts":1,
"onFailure":"Continue",
"inputs":[
"ResourceType":"EC2",
"ResourceIds":[
"{{createImage.ImageId}}"
],
"Tags":[
{
"Key": "Generated By Automation",
"Value: "{{automation:EXECUTION_ID}}"
},
{
"Key": "From Source AMI",
"Value: "{{sourceAMIid}}"
}
]
}
},
{
"name":"terminateInstance",
"action":"aws:changeInstanceState",
"maxAttempts":1,
"onFailure":"Continue",
"inputs":{
"InstanceIds":[
"{{ startInstances.InstanceIds }}"
],
"DesiredState":"terminated"
}
}
],
"outputs":[
"createImage.ImageId"
]
}

Running scripts

creating instance

Caling a lambda function

Hexo Blogs

This blog

Is written in hexo. Hexo is simply a node project that presents markdown files in a pretty way (as a blog). As its markdown its pretty convinient for a blog about development, as you will find a lot of documentation in this format.

With the admin plugin it almost fells like wordpress, but with all the code completly customizable. The plugin makes it way easier to manage your blog.

1
2
// This command will generate all the static files that you need for your blog
$ hexo generate
1
2
//This command simply starts the server, so you can see you blog before you deploy it.
$ hexo server
Deploy/host

How to host and deploy your blog is up to you. Every hexo blog comes with a _config.yml file, for all the settings of your project. One of the things you can specify is, what and where you want to deploy your static files.
In depth you can read more about it here: Hexo documentation

I have set this up to github pages, as this blog only consists of static files.
My deploy configuration looks like the following.

1
2
3
4
deploy:
type: git
repository: https://github.com/emilhein/emilhein.github.com.git
branch: master

Then when i run the floowing command my files will be deployed and saved in sourcecontrol

1
2
// This command will generate all the static files that you need for your blog
$ hexo deploy [commit message]

ES6 methods

I would like to learn more ES6 features, and therefore I will post my findings here. It’s just for fun and for my self to lookup.

Quick into

Let it be const

oh. The let and the const declaration of variables. Most likely 94 % of all js declarations uses the classic

1
var example = "this is a string";

This is all fine and good, but sometimes this gets confusing when dealing with scopes and duplicate declarations with the same name. For this purpose the word LET, comes to the rescue. look at the following pieces of code:

1
2
3
4
5
6
7
8
var Animal = "Panda";

while(true){
var Animal = "Rhino";
console.log(Animal); // -> Rhino
}

console.log(Animal); // -> Rhino

and

1
2
3
4
5
6
7
8
let Animal = "Panda";

while(true){
let Animal = "Rhino";
console.log(Animal); // -> Rhino
}

console.log(Animal); // -> Panda

This is due to the scoping of “let”, which will only be in scope of the next bracket. In the case of “var”, javascript uses something called Hoisting, which in short means that the code gets transformed into something like this:

1
2
3
4
5
6
7
8
9
10
var Animal;

Animal = "Panda";

while(true){
Animal = "Rhino";
console.log(Animal); // -> Rhino
}

console.log(Animal); // -> Rhino

Decunstruction

This is awesome for handling optional values to a method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// default values in the method signature and descrructuring
function deconstruc({
size,
price,
address = "unknown"
})
{

console.log('your house is: ' + size +' squarefeet, costs: ' + price +' and the address is ' + address);
}

var house = {
'size': 123,
'land': 2234,
'address': 'Fifth avenue 2',
'price': 1250000
};
var house2 = {
'size': 123,
'land': 2234,
'price': 1250000

};
deconstruc(house);
deconstruc(house2);