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 / terraform.tf
Created January 5, 2019 11:05
Config GCP as Terraform provider
provider "google" {
credentials = "${file("${var.credentials}")}"
project = "${var.project}"
region = "${var.region}"
}
@mlabouardy
mlabouardy / deploy.sh
Last active December 1, 2018 12:31
Deploy Ruby based Lambda function
zip -r deployment.zip handler.rb
aws lambda update-function-code --function-name ScanMovies --zip-file fileb://./deployment.zip
@mlabouardy
mlabouardy / policy.json
Created December 1, 2018 11:51
IAM policy to invoke Scan operation on DynamoDB table
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Action": "dynamodb:Scan",
"Resource": [
"arn:aws:dynamodb:eu-west-3:*:table/movies",
"arn:aws:dynamodb:eu-west-3:*:table/movies/index/*"
@mlabouardy
mlabouardy / handler.rb
Created December 1, 2018 11:47
Ruby Lambda Function
require 'aws-sdk'
require 'json'
def lambda_handler(event:, context:)
dynamodb = Aws::DynamoDB::Client.new(region: ENV['AWS_REGION'])
resp = dynamodb.scan({
table_name: ENV['TABLE_NAME'],
})
{ statusCode: 200, body: JSON.generate(resp.items) }
@mlabouardy
mlabouardy / index.js
Last active November 25, 2018 16:40
Lambda edge redirect based on browser language
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request
const headers = request.headers
if(request.uri == '/') {
if (typeof headers['accept-language'] !== 'undefined') {
const supportedLanguages = headers['accept-language'][0].value
console.log('Supported languages:', supportedLanguages)
if(supportedLanguages.startsWith('en')){
callback(null, redirect('/en/'))
} else if(supportedLanguages.startsWith('fr')){
@mlabouardy
mlabouardy / cognito-auth.sh
Created November 18, 2018 20:57
Sign in with AWS Cognito CLI
aws cognito-idp admin-initiate-auth -region AWS_REGION -cli-input-json file://input.json
@mlabouardy
mlabouardy / cognito-output.json
Created November 18, 2018 15:11
AWS Cognito authentication output
{
"AuthenticationResult": {
"ExpiresIn": 3600,
"IdToken": "ID_TOKEN",
"RefreshToken": "REFRESH_TOKEN",
"TokenType": "Bearer",
"AccessToken": "ACCESS_TOKEN"
},
"ChallengeParameters": {}
}
@mlabouardy
mlabouardy / cognito-input.json
Created November 18, 2018 15:09
Cognito Auth input
{
"UserPoolId": "USER_POOL",
"ClientId": "CLIENT_ID",
"AuthFlow": "ADMIN_NO_SRP_AUTH",
"AuthParameters": {
"USERNAME": "USERNAME",
"PASSWORD": "PASSWORD"
}
}
@mlabouardy
mlabouardy / cognito.sh
Created November 18, 2018 15:07
Create and confirm a user on AWS Cognito
# Create a user
aws cognito-idp sign-up -region AWS_REGION -client-id CLIENT_ID \
-username USERNAME -password PASSWORD -user-attributes Name=email,Value=EMAIL
# Confirm sign up
aws cognito-idp admin-confirm-sign-up -region AWS_REGION -user-pool-id USER_POOL \
-username USERNAME
@mlabouardy
mlabouardy / policy.json
Created November 18, 2018 15:04
Manage DynamoDB table
{
"Version": "2012–10–17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:DeleteItem",