Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
diogoaurelio / lambda_module_instantiation.tf
Last active September 16, 2018 11:44
lambda_module_instantiation.tf
module "redshift_loader_lambda" {
source = "github.com/diogoaurelio/terraform-aws-lambda-module"
version = "v0.0.1"
aws_region = "${var.aws_region}"
environment = "${var.environment}"
project = "${var.project}"
lambda_unique_function_name = "${var.redshift_loader_lambda_unique_function_name}"
@diogoaurelio
diogoaurelio / redshift_lambda_data_loader.py
Last active March 8, 2022 19:38
Sample code tfor a S3 triggered AWS Lambda function to issue Copy command to load data into Redshift DB
import urllib
import pg8000
import boto3
import os
import logging
IAM_ROLE = os.environ['IAM_ROLE']
DB_NAME = os.environ['DB_NAME']
DB_USER = os.environ['DB_USER']
DB_PORT = os.environ['DB_PORT']
trait Actor {
final def sender(): ActorRef = context.sender()
}
import akka.actor.Actor
import akka.actor.Props
import akka.event.Logging
class DudeA extends Actor {
val log = Logging(context.system, this)
def receive = {
case "hello" => sender() ! "Hallo, Grüß Dich!"
case _ => log.info("Hmm...")
@diogoaurelio
diogoaurelio / scalaActorTrait.scala
Created December 20, 2017 13:45
summaryScalaActorTrait
trait Actor {
// to make type Receive known in subclasses without import
type Receive = Actor.Receive
// [...]
//#receive
def receive: Actor.Receive
// [...]
}
@diogoaurelio
diogoaurelio / basicActorClass.scala
Created December 20, 2017 13:42
Basic Scala Actor Class
import akka.actor.Actor
import akka.actor.Props
import akka.event.Logging
class MyActor extends Actor {
val log = Logging(context.system, this)
var myMutatedVar: Int = 0
def receive = {
case "test" => log.info("received test")
case "mutate" => myMutatedVar += 1; log.info(s"Mutated var to: $myMutatedVar")
@diogoaurelio
diogoaurelio / iam.tf
Created December 3, 2017 15:31 — forked from clstokes/iam.tf
variable "role_name" {}
variable "role_policy_file" {}
resource "aws_iam_role" "role" {
name = "${var.role_name}"
assume_role_policy = "${file("${path.module}/policies/${var.role_policy_file}")}"
}
output "role_arn" {
value = "${aws_iam_role.role.arn}"
@diogoaurelio
diogoaurelio / aws_instance_temp_credentials.py
Created December 1, 2017 11:11
aws_instance_temp_credentials.py
def get_temp_credentials(role=DEFAULT_INSTANCE_ROLE):
""" Retrieves temp AWS credentials """
query_uri = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/{}'.format(role)
print('Querying AWS for credentials - {}'.format(query_uri))
try:
sts_credentials = requests.get(query_uri).json()
if isinstance(sts_credentials, dict) and \
sts_credentials.get('Code') == 'Success':
print('Successfully retrieved temp AWS credentials.')
return sts_credentials
@diogoaurelio
diogoaurelio / assume-role-policy.json
Created November 25, 2017 17:05 — forked from clstokes/assume-role-policy.json
Example: Terraform IAM Role
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
@diogoaurelio
diogoaurelio / aws_assume_role_sample.py
Created November 23, 2017 20:54
aws_assume_role_sample.py
import boto3
def role_arn_to_session(**args):
"""
Usage :
session = role_arn_to_session(
RoleArn='arn:aws:iam::012345678901:role/example-role',
RoleSessionName='ExampleSessionName')
client = session.client('sqs')
"""