Skip to content

Instantly share code, notes, and snippets.

@tnolet tnolet/s3dynamo.go
Last active Jan 19, 2018

Embed
What would you like to do?
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/s3"
"io/ioutil"
)
func Handler() (events.APIGatewayProxyResponse, error) {
resultS3, err := fetchS3()
if err != nil {
fmt.Println(err)
}
fmt.Println(resultS3)
_, err = ioutil.ReadAll(resultS3.Body)
if err != nil {
fmt.Println(err)
}
resultDD, err := putDynamoDB(resultS3.LastModified.String())
if err != nil {
fmt.Println(err)
}
fmt.Println(resultDD)
return events.APIGatewayProxyResponse{
Body: "done",
StatusCode: 200,
}, nil
}
func main() {
lambda.Start(Handler)
}
func fetchS3() (*s3.GetObjectOutput, error) {
svcS3 := s3.New(session.New())
input := &s3.GetObjectInput{
Bucket: aws.String("staging.vamp.io"),
Key: aws.String("img/006-mock-ups/VAMP-light-laptop-v091-hero.png"),
}
return svcS3.GetObject(input)
}
func putDynamoDB(msg string) (*dynamodb.PutItemOutput, error) {
svcDynamo := dynamodb.New(session.New())
input := &dynamodb.PutItemInput{
Item: map[string]*dynamodb.AttributeValue{
"message": {
S: aws.String(msg),
},
},
TableName: aws.String("loadtestlambda"),
}
return svcDynamo.PutItem(input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.