How to setup https (NGINX) for AWS + Unity projects

Step 1. Buy ssl certificate from a vendor. I bought from godaddy because my domain was from godaddy.com

Step2. Create your .key and then a .csr from the .key on the EC2 instance

Step3. The vendor (godaddy in my case) will take the .csr file and give 2 .cert files. These two files will be .csr and bundle*.csr . Combine these as shown here

Step 4. Copy the files in a secure location and use as described here

That’s how I made https://www.gogameserver.com work.

Currently FreakBall uses that as backend.

AWS: Cross region ECS docker registry support

Let’s say you have a docker registry in US-east-1 and you want to pull the registry in eu-central-1.

1. Add this in the IAM role of the EC2 machine

{
  "Effect": "Allow", 
  "Action": [ 
    "ecr:GetAuthorizationToken", 
    "ecr:BatchCheckLayerAvailability", 
    "ecr:GetDownloadUrlForLayer", 
    "ecr:GetRepositoryPolicy",   
    "ecr:DescribeRepositories", 
    "ecr:ListImages", 
    "ecr:BatchGetImage", 
    "ecr:InitiateLayerUpload", 
    "ecr:UploadLayerPart", 
    "ecr:CompleteLayerUpload", 
    "ecr:PutImage" ], 
  "Resource": "*" 
}

2. Set the mtu value

sudo ifconfig eth0 mtu 1500

3. Login

$(aws ecr get-login --region us-east-1)

4. Pull the docker image:

docker pull https://acc_id.dkr.ecr.us-east-1.amazonaws.com/image

Any questions? Please comment.

Golang: Get EC2 AWS instance region

Following is the golang code to get the region of an EC2 machine in AWS.

package main

import (
        "fmt"
    "io/ioutil"
    "net/http"
)

func getRegion() string{
    link := "http://169.254.169.254/latest/meta-data/placement/availability-zone"
    response, err := http.Get(link)
    if err != nil {
        fmt.Println(err)
    }
    defer response.Body.Close()

    //block forever at the next line
    content, _ := ioutil.ReadAll(response.Body)

    return string(content)
}

func main() {
    aws_region := getRegion()
    fmt.Println(aws_region)

}