Everybody's Changing

and I don't feel the same.

Create an EC2 Instance in CLI

Create a Windows instance with Name tag containing current datetime and user data that will download a file from Amazon S3 by using PowerShell.

– create_instance.sh


DATE=`date +"%y%m%d_%H%M%S"`

TAGS="ResourceType=instance,Tags=[{Key=Name,Value=server_${DATE}},{Key=Managed,Value=''}] ResourceType=volume,Tags=[{Key=Name,Value=server_${DATE}}]"

instanceId=`aws ec2 run-instances --iam-instance-profile Name=CodeDeployS3Role --image-id ami-12345678 --count 1 --instance-type t2.micro --key-name server-key --security-group-ids sg-12345678 --subnet-id subnet-12345678 --associate-public-ip-address --user-data file:///home/ec2-user/user_data.txt --tag-specifications ${TAGS} --query 'Instances[0].InstanceId' --output text`

echo $instanceId

aws elb register-instances-with-load-balancer --load-balancer-name server-lb --instances $instanceId

– user_data.txt

net stop DatadogAgent

$localIp = (Invoke-RestMethod -Method Get -Uri
$externalIp = (Invoke-RestMethod -Method Get -Uri
$hostname = (Invoke-RestMethod -Method Get -Uri

echo $localIp | Out-File -FilePath c:\ip_new.txt -Encoding ASCII
echo $externalIp | Out-File -FilePath c:\ip_new.txt -Encoding ASCII -Append

mkdir C:\deploy

Read-S3Object -AccessKey ACCESS_KEY -SecretKey SECRET_KEY -Region us-east-1 -BucketName BUCKET_NAME -Key dist/file.zip -File C:\deploy\latest.zip

& "C:\Program Files\Java\jdk1.8.0_131\bin\jar.exe" xf C:\deploy\latest.zip

Remove-Item -Force -Recurse C:\Bin\Release
Remove-Item -Force -Recurse C:\Bin\Support
Copy-Item -Force -Recurse C:\deploy\Release -Destination C:\Bin\Release
Copy-Item -Force -Recurse C:\deploy\Support -Destination C:\Bin\Support

Remove-Item -Force -Recurse C:\deploy

(Get-Content C:\ProgramData\Datadog\datadog.conf).replace('[HOSTNAME]', $hostname) | Set-Content C:\ProgramData\Datadog\datadog.conf
(Get-Content C:\ProgramData\Datadog\conf.d\tcp_check.yaml).replace('[HOSTNAME]', $hostname) | Set-Content C:\ProgramData\Datadog\conf.d\tcp_check.yaml

net start DatadogAgent

Integrating AWS CodeDeploy with Slack

This article describes how to integrate AWS CodeDeploy with Slack, so we will be able to receive deployment notifications in the Slack channel. Here’s what we need to do.

1. Create an Incoming WebHooks in Slack
2. Create a Lambda function that sends a message to Slack Webhook URL
3. Create a SNS Topic and Make the Lambda function subscribe to the Topic
4. Create a trigger in CodeDeploy project to send notifications to the SNS Topic

Step 1. Create an Incoming WebHooks in Slack

The Webhook URL will be used in the Lambda function.

Step 2. Create a Lambda function that sends messages to Slack Webhook URL

Download the node.js script from https://gist.github.com/MrRoyce/097edc0de2fe001288be2e8633f4b22a Or, copy and paste the code below.

var services = '/services/...';  // Update this with your Slack service...
var channel = "#aws-deployments"  // And this with the Slack channel

var https = require('https');
var util = require('util');

var formatFields = function(string) {
    message = JSON.parse(string),
    fields  = [],

  // Make sure we have a valid response
  if (message) {
    fields = [
        "title" : "Task",
        "value" : message.eventTriggerName,
        "short" : true
        "title" : "Status",
        "value" : message.status,
        "short" : true
        "title" : "Application",
        "value" : message.applicationName,
        "short" : true
        "title" : "Deployment Group",
        "value" : message.deploymentGroupName,
        "short" : true
        "title" : "Region",
        "value" : message.region,
        "short" : true
        "title" : "Deployment Id",
        "value" : message.deploymentId,
        "short" : true
        "title" : "Create Time",
        "value" : message.createTime,
        "short" : true
        "title" : "Complete Time",
        "value" : ((message.completeTime) ? message.completeTime : ''),
        "short" : true

    if (message.deploymentOverview) {
     deploymentOverview = JSON.parse(message.deploymentOverview);
          "title" : "Succeeded",
          "value" : deploymentOverview.Succeeded,
          "short" : true
          "title" : "Failed",
          "value" : deploymentOverview.Failed,
          "short" : true
          "title" : "Skipped",
          "value" : deploymentOverview.Skipped,
          "short" : true
          "title" : "In Progress",
          "value" : deploymentOverview.InProgress,
          "short" : true
          "title" : "Pending",
          "value" : deploymentOverview.Pending,
          "short" : true

  return fields;


exports.handler = function(event, context) {

    var postData = {
        "channel": channel,
        "username": "AWS SNS via Lamda :: CodeDeploy Status",
        "text": "*" + event.Records[0].Sns.Subject + "*",
        "icon_emoji": ":aws:"

    var fields = formatFields(event.Records[0].Sns.Message);
    var message = event.Records[0].Sns.Message;
    var severity = "good";

    var dangerMessages = [
        " but with errors",
        " to RED",
        "During an aborted deployment",
        "Failed to deploy application",
        "Failed to deploy configuration",
        "has a dependent object",
        "is not authorized to perform",
        "Pending to Degraded",
        "Stack deletion failed",
        "Unsuccessful command execution",
        "You do not have permission",
        "Your quota allows for 0 more running instance"];

    var warningMessages = [
        " aborted operation.",
        " to YELLOW",
        "Adding instance ",
        "Degraded to Info",
        "Deleting SNS topic",
        "is currently running under desired capacity",
        "Ok to Info",
        "Ok to Warning",
        "Pending Initialization",
        "Removed instance ",
        "Rollback of environment"

    for(var dangerMessagesItem in dangerMessages) {
        if (message.indexOf(dangerMessages[dangerMessagesItem]) != -1) {
            severity = "danger";

    // Only check for warning messages if necessary
    if (severity == "good") {
        for(var warningMessagesItem in warningMessages) {
            if (message.indexOf(warningMessages[warningMessagesItem]) != -1) {
                severity = "warning";

    postData.attachments = [
            "color": severity,
            "fields": fields

    var options = {
        method: 'POST',
        hostname: 'hooks.slack.com',
        port: 443,
        path: services  // Defined above

    var req = https.request(options, function(res) {
      res.on('data', function (chunk) {

    req.on('error', function(e) {
      console.log('problem with request: ' + e.message);

    req.write(util.format("%j", postData));

Create a Lambda function with replacing Webhook URL and channel.

Step 3. Create a SNS Topic and Make the Lambda function subscribe to the Topic

Step 4. Create a trigger in CodeDeploy project to send notifications to the SNS Topic

Finally, we can receive deployment notifications.

Upgrade FreeNAS machine

I used Supermicro X7SPA-H-D525 which is integrated with Atom D525(Dual Core, 1.8GHz) as my NAS for last 5 years.

Recently, I was looking for a home media server and found that Plex can manage all kinds of media such as photos, videos, movie and TV shows. Plex also can be accessible from most devices like computers, smartphones, tablets and even TV. It’s amazing!

After setting up Plex on my NAS, I realized that Atom D525 is not enough for transcoding. So, I decided to upgrade my NAS box!

– Supermicro X9SRI-F
– Intel Xeon Quad-Core E5-2603
– DDR3 PC3-10600 (1,333Mhz) 8GB
– Lian-li PC-7NA
– HGST HDN724030 3TB
Hitachi HDS721 1TB
Hitachi HDS5C3 2TB
Hitachi HDS5C3 2TB
Hitachi HDS5C3 2TB
ST500NM0011 500GB







Page 1 of 56

Powered by WordPress & Theme by Anders Norén