Skip to content

Instantly share code, notes, and snippets.

Last active March 14, 2023 23:40
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ECS / EC2 Metadata entrypoint example
FROM golang:1.4
COPY main.go main.go
RUN go build -o main main.go
RUN chmod +x /
CMD ["./main"]
export HOST=$(curl --retry 5 --connect-timeout 3 -s
export LOCAL_IP=$(curl --retry 5 --connect-timeout 3 -s
exec "$@"
package main
import (
func main() {
log.Fatal(http.ListenAndServe(":8080", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
resp.Header().Set("Content-Type", "application/json")
body, err := json.Marshal(map[string]string{"hostname": os.Getenv("HOST"), "localIp": os.Getenv("LOCAL_IP")})
if err != nil {
"family": "test-hostenv-entrypoint",
"containerDefinitions": [{
"name": "test",
"image": "euank/play:2015-08-10",
"memory": 50,
"portMappings": [{
"containerPort": 8080,
"hostPort": 8080
Copy link

Thank for this, I will try later today. The issue I have had in my attempts is the session the export of the variables is placed. I am using a Spring/Java jar file. Needing to get the env variables into the properties files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment