Skip to content

Commit

Permalink
Draft for put landing page; identified TODOs
Browse files Browse the repository at this point in the history
Issue: #25
  • Loading branch information
rivernews committed Sep 25, 2022
1 parent eb61eef commit ec37c70
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lambda_golang/cmd/landing_s3_trigger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main
import (
"context"
"fmt"
"strings"

//"math"

Expand All @@ -17,9 +16,10 @@ import (
//"github.com/aws/aws-sdk-go-v2/config"
//"github.com/aws/aws-sdk-go-v2/service/sqs"

"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"

// local packages
"github.com/rivernews/media-literacy/pkg/cloud"
"github.com/rivernews/media-literacy/pkg/newssite"
)

func main() {
Expand All @@ -44,6 +44,13 @@ func HandleRequest(ctx context.Context, s3Event events.S3Event) (LambdaResponse,

// TODO: push into dynamoDB instead

cloud.DynamoDBPutItem(ctx, map[string]types.AttributeValue{
"s3Key": &types.AttributeValueMemberS{Value: "12346"},
"docType": &types.AttributeValueMemberS{Value: "John Doe"},
"events": &types.AttributeValueMemberS{Value: "john@doe.io"},
"isDocTypeWaitingForMetadata": &types.AttributeValueMemberS{Value: "TODO"},
})

// TODO: let landing s3 trigger switch to point to this func

// landingPageHtmlText := cloud.Pull(landingPageS3Key)
Expand Down
11 changes: 7 additions & 4 deletions lambda_golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/PuerkitoBio/goquery v1.7.1
github.com/aws/aws-lambda-go v1.26.0
github.com/aws/aws-sdk-go-v2 v1.16.15
github.com/aws/aws-sdk-go-v2 v1.16.16
github.com/aws/aws-sdk-go-v2/config v1.7.0
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.14.0
Expand All @@ -14,22 +14,25 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.17 // indirect
)

require (
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.17.1
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.6.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sfn v1.14.0
github.com/aws/aws-sdk-go-v2/service/sso v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect
github.com/aws/smithy-go v1.13.3 // indirect
github.com/google/uuid v1.3.0
github.com/jmespath/go-jmespath v0.4.0 // indirect
golang.org/x/text v0.3.6 // indirect
)
14 changes: 14 additions & 0 deletions lambda_golang/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/aws/aws-lambda-go v1.26.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XO
github.com/aws/aws-sdk-go-v2 v1.9.0/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4=
github.com/aws/aws-sdk-go-v2 v1.16.15 h1:2sInOWGE4HV54R90Pj8QgqBBw3Qf1I0husqbqjPZzys=
github.com/aws/aws-sdk-go-v2 v1.16.15/go.mod h1:SwiyXi/1zTUZ6KIAmLK5V5ll8SiURNUYOqTerZPaF9k=
github.com/aws/aws-sdk-go-v2 v1.16.16 h1:M1fj4FE2lB4NzRb9Y0xdWsn2P0+2UHVxwKyOa4YJNjk=
github.com/aws/aws-sdk-go-v2 v1.16.16/go.mod h1:SwiyXi/1zTUZ6KIAmLK5V5ll8SiURNUYOqTerZPaF9k=
github.com/aws/aws-sdk-go-v2/config v1.7.0 h1:J2cZ7qe+3IpqBEXnHUrFrOjoB9BlsXg7j53vxcl5IVg=
github.com/aws/aws-sdk-go-v2/config v1.7.0/go.mod h1:w9+nMZ7soXCe5nT46Ri354SNhXDQ6v+V5wqDjnZE+GY=
github.com/aws/aws-sdk-go-v2/credentials v1.4.0 h1:kmvesfjY861FzlCU9mvAfe01D9aeXcG2ZuC+k9F2YLM=
Expand All @@ -18,12 +20,22 @@ github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.0 h1:zzH1xd1/PX7bFO4/BQwVQP
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.0/go.mod h1:fPU0eFGnS47RyKHHs8BNcCKOm5oOA5xm0BlrZWsQT/A=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.22 h1:pE27/u2A7JlwICjOvONQDob8PToShRTkuiUE74ymVWg=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.22/go.mod h1:/vNv5Al0bpiF8YdX2Ov6Xy05VTiXsql94yUqJMYaj0w=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.23 h1:s4g/wnzMf+qepSNgTvaQQHNxyMLKSawNhKCPNy++2xY=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.23/go.mod h1:2DFxAQ9pfIRy0imBCJv+vZ2X6RKxves6fbnEuSry6b4=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.16 h1:L5LKGHHXOl4t7+5QZMTl38GIzSAq07XUTRtEquiHGMA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.16/go.mod h1:62dsXI0BqTIGomDl8Hpm33dv0OntGaVblri3ZRParVQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.17 h1:/K482T5A3623WJgWT8w1yRAFK4RzGzEl7y39yhtn9eA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.17/go.mod h1:pRwaTYCJemADaqCbUAxltMoHKata7hmB5PjEXeu0kfg=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.2 h1:d95cddM3yTm4qffj3P6EnP+TzX1SSkWaQypXSgT/hpA=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.2/go.mod h1:BQV0agm+JEhqR+2RT5e1XTFIDcAAV0eW6z2trp+iduw=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.17.1 h1:1QpTkQIAaZpR387it1L+erjB5bStGFCJRvmXsodpPEU=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.17.1/go.mod h1:BZhn/C3z13ULTSstVi2Kymc62bgjFh/JwLO9Tm2OFYI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.3.0 h1:gceOysEWNNwLd6cki65IMBZ4WAM0MwgBQq2n7kejoT8=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.3.0/go.mod h1:v8ygadNyATSm6elwJ/4gzJwcFhri9RqS8skgHKiwXPU=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.9 h1:Lh1AShsuIJTwMkoxVCAYPJgNG5H+eN6SmoUn8nOZ5wE=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.9/go.mod h1:a9j48l6yL5XINLHLcOKInjdvknN+vWqPBxqeIDw7ktw=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.17 h1:o0Ia3nb56m8+8NvhbCDiSBiZRNUwIknVWobx5vks0Vk=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.17/go.mod h1:WJD9FbkwzM2a1bZ36ntH6+5Jc+x41Q4K2AcLeHDLAS8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.0 h1:VNJ5NLBteVXEwE2F1zEXVmyIH58mZ6kIQGJoC7C+vkg=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.0/go.mod h1:R1KK+vY8AfalhG1AOu5e35pOD2SdoPKQCFLTvnxiohk=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.6.0 h1:B/1pIeV/oFnrOwhoMA6ASX+qT4FzMqn1MYsPiIXgMqQ=
Expand All @@ -48,6 +60,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand Down
51 changes: 51 additions & 0 deletions lambda_golang/pkg/cloud/dynamodb_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cloud

import (
"context"
"sync"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/rivernews/GoTools"

"github.com/google/uuid"
)

var (
dynamoDBClient *dynamodb.Client
dynamoDBClientOnce sync.Once
)

func SharedDynamoDBClient() *dynamodb.Client {
dynamoDBClientOnce.Do(func() {
dynamoDBClient = dynamodb.NewFromConfig(ShareAWSConfig())
})
return dynamoDBClient
}

func DynamoDBPutItem(ctx context.Context, item map[string]types.AttributeValue) *dynamodb.PutItemOutput {
tableID := GoTools.GetEnvVarHelper("MEDIA_TABLE_ID")
if tableID == "" {
GoTools.Logger("ERROR", "MEDIA_TABLE_ID is required please set this env var")
}

if _, exist := item["uuid"]; !exist {
item["uuid"] = uuid.New().String()
}

if _, exist := item["createdAt"]; !exist {
// TODO
}

out, err := dynamoDBClient.PutItem(ctx, &dynamodb.PutItemInput{
TableName: aws.String(tableID),
Item: item,
})

if err != nil {
GoTools.Logger("ERROR", err.Error())
}

return out
}

0 comments on commit ec37c70

Please sign in to comment.