Skip to content

Instantly share code, notes, and snippets.

View rogerwelin's full-sized avatar
:shipit:
Gopher

Roger Welin rogerwelin

:shipit:
Gopher
View GitHub Profile
@rogerwelin
rogerwelin / ring.go
Created November 16, 2018 09:08
ring
package main
import (
"container/ring"
"fmt"
"strconv"
)
func main() {
@rogerwelin
rogerwelin / stack.go
Last active November 16, 2018 12:12
stack.go
package main
import (
"errors"
"fmt"
)
type Stack struct {
s []int
}
variable "region" {
default = "us-east-1"
}
variable "website_bucket" {
default = "weather-api-website1"
}
variable "artifact_bucket" {
default = "12345-artifact-bucket"
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
variable "region" {
description = "specifies aws region"
default = "us-east-1"
}
variable "artifact_bucket" {
description = "the bucket for fetching the artifact"
default = "12345-artifact-bucket"
}
provider "aws" {
region = "${var.region}"
}
############################################
# IAM - Role & Permissions for our lambda
############################################
resource "aws_iam_role" "lambda_role" {
name = "serverless_website_lambda"
############################################
# LAMBDA - Create the lambda function
############################################
resource "aws_lambda_function" "weather_api" {
function_name = "weather-api"
# fetch the artifact from bucket created earlier
s3_bucket = "${var.artifact_bucket}"
s3_key = "${var.artifact_zip_name}"
############################################
# API GATEWAY - Sets up & configure api gw
############################################
resource "aws_api_gateway_rest_api" "weather_gw" {
name = "weather-api"
description = "created by terraform"
}
resource "aws_api_gateway_resource" "proxy" {
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
body {
padding-top: 30px;
padding-left: 60px;
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"sync"
"github.com/aws/aws-lambda-go/events"