Skip to content

Instantly share code, notes, and snippets.

View elliotforbes's full-sized avatar
:octocat:

Elliot Forbes elliotforbes

:octocat:
View GitHub Profile
resource "aws_security_group" "elb" {
name = "terraform-go-api"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_launch_configuration" "example" {
image_id = "ami-58d7e821"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.instance.id}"]
user_data = <<-EOF
#!/bin/bash
echo "Hello, World" > index.html
provider "aws" {
access_key = "xxx"
secret_key = "xxxxx"
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-2757f631"
instance_type = "t2.micro"
}
>>> import boto3
>>> rekognition = boto3.client('rekognition', 'eu-west-1')
>>> response = rekognition.detect_labels(Image={"S3Object":{"Bucket":"imgur-serverless-v2", "Name": "dogs.jpg" }})
>>> response
{'Labels': [{'Name': 'Animal', 'Confidence': 92.09390258789062}, {'Name': 'Canine', 'Confidence': 92.09390258789062}, {'Name': 'Collie', 'Confidence': 92.09390258789062}, {'Name': 'Dog', 'Confidence': 92.09390258789062}, {'Name': 'Mammal', 'Confidence': 92.09390258789062}, {'Name': 'Pet', 'Confidence': 92.09390258789062}, {'Name': 'Husky', 'Confidence': 53.51436233520508}, {'Name': 'Eskimo Dog', 'Confidence': 51.68663787841797}],'OrientationCorrection': 'ROTATE_0', 'ResponseMetadata': {'RequestId': '3826c201-1a50-11e8-9262-597ffc9fcbba', 'HTTPStatusCode': 200, 'HTTPHeaders': {'content-type': 'application/x-amz-json-1.1', 'date': 'Sun, 25 Feb2018 17:20:47 GMT', 'x-amzn-requestid': '3826c201-1a50-11e8-9262-597ffc9fcbba', 'content-length': '436', 'connection': 'keep-alive'}, 'RetryAttempts': 0}}
import boto3
import os
import uuid
rekognition = boto3.client('rekognition', 'eu-west-1')
dynamo = boto3.resource('dynamodb', 'eu-west-1')
def tagImage(event, content):
key = uuid.uuid4().hex
location = event['Records'][0]['s3']['object']['key']
configure (config) {
if (typeof config !== 'object' || Array.isArray(config)) {
throw new Error('[CognitoAuth error] valid option object required')
}
this.userPool = new CognitoUserPool({
UserPoolId: config.IdentityPoolId,
ClientId: config.ClientId
})
Config.region = config.region
Config.credentials = new CognitoIdentityCredentials({
service: imgur-clone-functions
frameworkVersion: ">=1.1.0 <2.0.0"
custom:
bucket: imgur-serverless
provider:
name: aws
runtime: python3.6
import json
import boto3
from decimal import Decimal as D
dynamodb = boto3.resource('dynamodb', region_name="eu-west-1")
s3 = boto3.client('s3')
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, D):
const AWS = require('aws-sdk');
module.exports.requestUploadURL = (event, context, callback) => {
var s3 = new AWS.S3();
var params = JSON.parse(event.body);
var s3Params = {
Bucket: 'imgur-serverless',
Key: params.name,
ContentType: params.type,
service: imgur-clone-functions
frameworkVersion: ">=1.1.0 <2.0.0"
provider:
name: aws
runtime: python3.6
region: eu-west-1
iamRoleStatements: # permissions for all of your functions can be set here
- Effect: Allow