Skip to content

Instantly share code, notes, and snippets.

View mlabouardy's full-sized avatar
☁️
Subscribe to my newsletter ➡️ https://devopsbulletin.com

LABOUARDY Mohamed mlabouardy

☁️
Subscribe to my newsletter ➡️ https://devopsbulletin.com
View GitHub Profile
@mlabouardy
mlabouardy / assume-role-api.json
Created November 18, 2018 15:03
API Gateway assume role
{
"Version": "2012–10–17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Action": "sts:AssumeRole"
@mlabouardy
mlabouardy / index.js
Last active November 14, 2018 21:15
Lambda authorizer
const TOKEN = process.env.TOKEN;
const generatePolicy = (effect, methodArn) => {
return {
'policyDocument': {
'Version': '2012-10-17',
'Statement': [
{
'Sid': '1',
'Action': 'execute-api:Invoke',
@mlabouardy
mlabouardy / build.sh
Created November 4, 2018 15:08
Build a Go deployment package
# Build linux binary
GOOS=linux go build -o main main.go
# Create a zip file
zip deployment.zip main
@mlabouardy
mlabouardy / Jenkinsfile
Created November 4, 2018 12:54
CI/CD for Serverless apps with Jenkins
def bucket = 'deployment-packages-mlabouardy'
def functionName = 'Fibonacci'
def region = 'eu-west-3'
node('slaves'){
stage('Checkout'){
checkout scm
}
stage('Test'){
@mlabouardy
mlabouardy / lambda.sh
Created November 4, 2018 12:53
Create a AWS Lambda alias with CLI
aws lambda create-alias --function-name Fibonacci \
--name production --function-version 2 \
--region eu-west-3
@mlabouardy
mlabouardy / Jenkinsfile
Created November 4, 2018 12:51
Publish Lambda function version with Jenkins
def bucket = 'deployment-packages-mlabouardy'
def functionName = 'Fibonacci'
def region = 'eu-west-3'
node('slaves'){
stage('Checkout'){
checkout scm
}
stage('Test'){
@mlabouardy
mlabouardy / Jenkinsfile
Created November 4, 2018 12:49
Jenkinsfile for Lambda functions
def bucket = 'deployment-packages-mlabouardy'
def functionName = 'Fibonacci'
def region = 'eu-west-3'
node('slaves'){
stage('Checkout'){
checkout scm
}
stage('Test'){
@mlabouardy
mlabouardy / lambda.tf
Created November 4, 2018 12:41
Go-based Lambda function with Terraform
// Lambda function
resource "aws_lambda_function" "function" {
filename = "deployment.zip"
function_name = "Fibonacci"
role = "${aws_iam_role.lambda_role.arn}"
handler = "main"
runtime = "go1.x"
}
@mlabouardy
mlabouardy / iam-lambda.tf
Created November 4, 2018 12:41
IAM role for Lambda function with Terraform
// Lambda IAM role
resource "aws_iam_role" "lambda_role" {
name = "FibonacciFunctionRole"
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
@mlabouardy
mlabouardy / iam-worker.tf
Created November 4, 2018 12:40
IAM instance profile with S3 and Lambda permissions
// Jenkins slave instance profile
resource "aws_iam_instance_profile" "worker_profile" {
name = "JenkinsWorkerProfile"
role = "${aws_iam_role.worker_role.name}"
}
resource "aws_iam_role" "worker_role" {
name = "JenkinsBuildRole"
path = "/"