From 3768127da1b735c4d432954390acf1b70ba17baa Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Sun, 17 Dec 2023 19:27:20 +0900 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20ARM=E3=81=A7=E3=82=82build=E3=81=8C?= =?UTF-8?q?=E9=81=A9=E5=88=87=E3=81=AB=E8=B5=B0=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/candle-backend.ts | 7 +++---- cdk.json | 2 +- lib/candle-backend-stack.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/candle-backend.ts b/bin/candle-backend.ts index 9c0b8ee..78e9016 100644 --- a/bin/candle-backend.ts +++ b/bin/candle-backend.ts @@ -18,8 +18,7 @@ new CandleBackendStack(app, 'CandleBackendStack', { // env: { account: '123456789012', region: 'us-east-1' }, /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ - - synthesizer: new cdk.DefaultStackSynthesizer({ - qualifier: 'candle', - }), + synthesizer: new cdk.DefaultStackSynthesizer({ + qualifier: "candle", + }), }); diff --git a/cdk.json b/cdk.json index a08006f..03207af 100644 --- a/cdk.json +++ b/cdk.json @@ -56,6 +56,6 @@ "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true, - "@aws-cdk/core:bootstrapQualifier": "candle" + "@aws-cdk/core:bootstrapQualifier": "candle" } } diff --git a/lib/candle-backend-stack.ts b/lib/candle-backend-stack.ts index 4ee13d5..679c4bf 100644 --- a/lib/candle-backend-stack.ts +++ b/lib/candle-backend-stack.ts @@ -46,7 +46,7 @@ export class CandleBackendStack extends cdk.Stack { 'bash', '-c', [ "export GOCACHE=/tmp/go-cache", "export GOPATH=/tmp/go-path", - "CGO_ENABLED=0 GOOS=linux go build -tags lambda.norpc -o /asset-output/bootstrap main.go", + "GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -tags lambda.norpc -o /asset-output/bootstrap main.go", ].join(" && "), ], }, From 7c1d954af60d684277e804812aaa68f773730a0b Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Thu, 14 Dec 2023 13:54:08 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20JetBrains=E3=81=AEIDE=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=9F=E9=9A=9B=E3=81=AB=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E8=BF=BD=E5=8A=A0=E3=81=95=E3=82=8C=E3=82=8B.idea/?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E8=B7=A1=E5=AF=BE=E8=B1=A1=E5=A4=96=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6e87812..d3eb767 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ node_modules cdk.out # planet scale credentials -.env \ No newline at end of file +.env + +.idea/ From c1ab8e3a155e4043fe3f328f46043c5aaba0b513 Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Thu, 14 Dec 2023 14:16:50 +0900 Subject: [PATCH 3/9] =?UTF-8?q?wip:=20room=20enter=E3=82=A8=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=9D=E3=82=A4=E3=83=B3=E3=83=88=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85(=E3=83=86=E3=82=B9=E3=83=88=E3=81=BE=E3=81=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/room/{room_id}/POST/go.mod | 24 ++++++- lambda/room/{room_id}/POST/go.sum | 51 ++++++++++++++ lambda/room/{room_id}/POST/main.go | 104 ++++++++++++++++++++++++++--- 3 files changed, 169 insertions(+), 10 deletions(-) diff --git a/lambda/room/{room_id}/POST/go.mod b/lambda/room/{room_id}/POST/go.mod index 8953b49..470043a 100644 --- a/lambda/room/{room_id}/POST/go.mod +++ b/lambda/room/{room_id}/POST/go.mod @@ -2,4 +2,26 @@ module room/room_id/POST go 1.21 -require github.com/aws/aws-lambda-go v1.42.0 // indirect +require ( + github.com/aws/aws-lambda-go v1.42.0 + github.com/aws/aws-sdk-go-v2 v1.24.0 + github.com/aws/aws-sdk-go-v2/config v1.26.1 + github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.6 +) + +require ( + github.com/aws/aws-sdk-go-v2/credentials v1.16.12 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 // indirect + github.com/aws/smithy-go v1.19.0 // indirect + github.com/google/uuid v1.5.0 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect +) diff --git a/lambda/room/{room_id}/POST/go.sum b/lambda/room/{room_id}/POST/go.sum index 725a484..4885429 100644 --- a/lambda/room/{room_id}/POST/go.sum +++ b/lambda/room/{room_id}/POST/go.sum @@ -1,2 +1,53 @@ github.com/aws/aws-lambda-go v1.42.0 h1:U4QKkxLp/il15RJGAANxiT9VumQzimsUER7gokqA0+c= github.com/aws/aws-lambda-go v1.42.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= +github.com/aws/aws-sdk-go-v2 v1.24.0 h1:890+mqQ+hTpNuw0gGP6/4akolQkSToDJgHfQE7AwGuk= +github.com/aws/aws-sdk-go-v2 v1.24.0/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= +github.com/aws/aws-sdk-go-v2/config v1.26.1 h1:z6DqMxclFGL3Zfo+4Q0rLnAZ6yVkzCRxhRMsiRQnD1o= +github.com/aws/aws-sdk-go-v2/config v1.26.1/go.mod h1:ZB+CuKHRbb5v5F0oJtGdhFTelmrxd4iWO1lf0rQwSAg= +github.com/aws/aws-sdk-go-v2/credentials v1.16.12 h1:v/WgB8NxprNvr5inKIiVVrXPuuTegM+K8nncFkr1usU= +github.com/aws/aws-sdk-go-v2/credentials v1.16.12/go.mod h1:X21k0FjEJe+/pauud82HYiQbEr9jRKY3kXEIQ4hXeTQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 h1:w98BT5w+ao1/r5sUuiH6JkVzjowOKeOJRHERyy1vh58= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10/go.mod h1:K2WGI7vUvkIv1HoNbfBA1bvIZ+9kL3YVmWxeKuLQsiw= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 h1:v+HbZaCGmOwnTTVS86Fleq0vPzOd7tnJGbFhP0stNLs= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9/go.mod h1:Xjqy+Nyj7VDLBtCMkQYOw1QYfAEZCVLrfI0ezve8wd4= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 h1:N94sVhRACtXyVcjXxrwK1SKFIJrA9pOJ5yu2eSHnmls= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9/go.mod h1:hqamLz7g1/4EJP+GH5NBhcUMLjW+gKLQabgyz6/7WAU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 h1:GrSw8s0Gs/5zZ0SX+gX4zQjRnRsMJDJ2sLur1gRBhEM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.6 h1:kSdpnPOZL9NG5QHoKL5rTsdY+J+77hr+vqVMsPeyNe0= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.6/go.mod h1:o7TD9sjdgrl8l/g2a2IkYjuhxjPy9DMP2sWo7piaRBQ= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 h1:/b31bi3YVNlkzkBrm9LfpaKoaYZUxIAj4sHfOTmLfqw= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4/go.mod h1:2aGXHFmbInwgP9ZfpmdIfOELL79zhdNYNmReK8qDfdQ= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10 h1:h8uweImUHGgyNKrxIUwpPs6XiH0a6DJ17hSJvFLgPAo= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10/go.mod h1:LZKVtMBiZfdvUWgwg61Qo6kyAmE5rn9Dw36AqnycvG8= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 h1:Nf2sHxjMJR8CSImIVCONRi4g0Su3J+TSTbS7G0pUeMU= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9/go.mod h1:idky4TER38YIjr2cADF1/ugFMKvZV7p//pVeV5LZbF0= +github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 h1:ldSFWz9tEHAwHNmjx2Cvy1MjP5/L9kNoR0skc6wyOOM= +github.com/aws/aws-sdk-go-v2/service/sso v1.18.5/go.mod h1:CaFfXLYL376jgbP7VKC96uFcU8Rlavak0UlAwk1Dlhc= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 h1:2k9KmFawS63euAkY4/ixVNsYYwrwnd5fIvgEKkfZFNM= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5/go.mod h1:W+nd4wWDVkSUIox9bacmkBP5NMFQeTJ/xqNabpzSR38= +github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 h1:5UYvv8JUvllZsRnfrcMQ+hJ9jNICmcgKPAO1CER25Wg= +github.com/aws/aws-sdk-go-v2/service/sts v1.26.5/go.mod h1:XX5gh4CB7wAs4KhcF46G6C8a2i7eupU19dcAAE+EydU= +github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM= +github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.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= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lambda/room/{room_id}/POST/main.go b/lambda/room/{room_id}/POST/main.go index 9977d98..03f0509 100644 --- a/lambda/room/{room_id}/POST/main.go +++ b/lambda/room/{room_id}/POST/main.go @@ -2,24 +2,110 @@ package main import ( "context" - "fmt" - + "encoding/json" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/dynamodb" + "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/google/uuid" + "net/http" + "os" ) -type Response struct { - Body string `json:"body"` +type Answer struct { + QuestionId string `json:"question_id"` + Answer bool `json:"answer"` +} +type UserData struct { + UserId string `json:"uid"` + NickName string `json:"nickname"` + Answers []Answer `json:"answers"` } -func handler(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { - fmt.Printf("room/{%s}/%s\n", event.PathParameters["room_id"], event.HTTPMethod) +type requestBody struct { + NickName string `json:"nickname"` + Answers []Answer `json:"answers"` +} + +func enterRoomHandler(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { + roomId := event.PathParameters["room_id"] + if roomId == "" { + return createEmptyResponseWithStatus(400, "Incorrect path parameter") + } + + var req requestBody + if err := json.Unmarshal([]byte(event.Body), &req); err != nil { + return createEmptyResponseWithStatus(500, "JSON parse error") + } + + //リクエストボディにuser_idは含まれていないので新しい構造体を使ってデータ挿入 + var userData UserData + userId := uuid.New() + + userData.UserId = userId.String() + userData.NickName = req.NickName + userData.Answers = req.Answers + + // 書き込み処理 + cfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + createEmptyResponseWithStatus(500, "") + } + + if err = insertUserDataToCandleBackendUserTable(cfg, ctx, userData); err != nil { + createEmptyResponseWithStatus(500, "Data write error.") + } + + jsonUserData, err := json.Marshal(userData) + if err != nil { + createEmptyResponseWithStatus(500, "JSON parse error.") + } return events.APIGatewayProxyResponse{ - Body: fmt.Sprintf("room/{%s}/%s", event.PathParameters["room_id"], event.HTTPMethod), - StatusCode: 200, + Body: string(jsonUserData), + StatusCode: http.StatusOK, }, nil } +func createEmptyResponseWithStatus(statusCode int, responseMessage string) (events.APIGatewayProxyResponse, error) { + return events.APIGatewayProxyResponse{ + Body: responseMessage, + StatusCode: statusCode, + }, nil +} + +func insertUserDataToCandleBackendUserTable(cfg aws.Config, ctx context.Context, userData UserData) error { + svc := dynamodb.NewFromConfig(cfg) + + tableName := "CandleBackendUserTable" + if t, exists := os.LookupEnv("USER_ABLE_NAME"); exists { + tableName = t + } + + var dynamoValue []types.AttributeValue + for _, ans := range userData.Answers { + answerMap := map[string]types.AttributeValue{ + "question_id": &types.AttributeValueMemberS{Value: ans.QuestionId}, + "answer": &types.AttributeValueMemberBOOL{Value: ans.Answer}, + } + dynamoValue = append(dynamoValue, &types.AttributeValueMemberM{Value: answerMap}) + } + + _, err := svc.PutItem(ctx, &dynamodb.PutItemInput{ + TableName: aws.String(tableName), + Item: map[string]types.AttributeValue{ + "user_id": &types.AttributeValueMemberS{Value: userData.UserId}, + "nickname": &types.AttributeValueMemberS{Value: userData.NickName}, + "answers": &types.AttributeValueMemberL{Value: dynamoValue}, + }, ConditionExpression: aws.String("attribute_not_exists(nickname,answers)"), + }) + if err != nil { + return err + } + return nil +} + func main() { - lambda.Start(handler) + lambda.Start(enterRoomHandler) } From 5269d88ee151c9f875e45964877cc4106f739769 Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Mon, 18 Dec 2023 01:27:47 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20dynbamodbav=E3=82=92=E6=A7=8B?= =?UTF-8?q?=E9=80=A0=E4=BD=93=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/room/{room_id}/POST/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lambda/room/{room_id}/POST/main.go b/lambda/room/{room_id}/POST/main.go index 03f0509..791ca3a 100644 --- a/lambda/room/{room_id}/POST/main.go +++ b/lambda/room/{room_id}/POST/main.go @@ -15,13 +15,13 @@ import ( ) type Answer struct { - QuestionId string `json:"question_id"` - Answer bool `json:"answer"` + QuestionId string `json:"question_id" dynamodbav:"question_id"` + Answer bool `json:"answer" dynamodbav:"answer"` } type UserData struct { - UserId string `json:"uid"` - NickName string `json:"nickname"` - Answers []Answer `json:"answers"` + UserId string `json:"uid" dynamodbav:"user_id"` + NickName string `json:"nickname" dynamodbav:"nickname"` + Answers []Answer `json:"answers" dynamodbav:"answers"` } type requestBody struct { From e9f677ca944431f2968102b6f950a9f6f9ab0982 Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Mon, 18 Dec 2023 03:43:58 +0900 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20DynamoDB=E3=81=B8=E3=81=AE=E6=9B=B8?= =?UTF-8?q?=E3=81=8D=E8=BE=BC=E3=81=BF=E6=99=82=E3=81=AE=E5=9E=8B=E3=81=AE?= =?UTF-8?q?=E6=89=B1=E3=81=84=E3=81=8C=E4=B8=8D=E9=81=A9=E5=88=87=E3=81=A0?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/room/{room_id}/POST/go.mod | 3 ++- lambda/room/{room_id}/POST/go.sum | 2 ++ lambda/room/{room_id}/POST/main.go | 24 +++++++++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lambda/room/{room_id}/POST/go.mod b/lambda/room/{room_id}/POST/go.mod index 470043a..4d197e9 100644 --- a/lambda/room/{room_id}/POST/go.mod +++ b/lambda/room/{room_id}/POST/go.mod @@ -4,9 +4,11 @@ go 1.21 require ( github.com/aws/aws-lambda-go v1.42.0 + github.com/aws/aws-sdk-go v1.49.4 github.com/aws/aws-sdk-go-v2 v1.24.0 github.com/aws/aws-sdk-go-v2/config v1.26.1 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.6 + github.com/google/uuid v1.5.0 ) require ( @@ -22,6 +24,5 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 // indirect github.com/aws/smithy-go v1.19.0 // indirect - github.com/google/uuid v1.5.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect ) diff --git a/lambda/room/{room_id}/POST/go.sum b/lambda/room/{room_id}/POST/go.sum index 4885429..17dbb11 100644 --- a/lambda/room/{room_id}/POST/go.sum +++ b/lambda/room/{room_id}/POST/go.sum @@ -1,5 +1,7 @@ github.com/aws/aws-lambda-go v1.42.0 h1:U4QKkxLp/il15RJGAANxiT9VumQzimsUER7gokqA0+c= github.com/aws/aws-lambda-go v1.42.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= +github.com/aws/aws-sdk-go v1.49.4 h1:qiXsqEeLLhdLgUIyfr5ot+N/dGPWALmtM1SetRmbUlY= +github.com/aws/aws-sdk-go v1.49.4/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go-v2 v1.24.0 h1:890+mqQ+hTpNuw0gGP6/4akolQkSToDJgHfQE7AwGuk= github.com/aws/aws-sdk-go-v2 v1.24.0/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= github.com/aws/aws-sdk-go-v2/config v1.26.1 h1:z6DqMxclFGL3Zfo+4Q0rLnAZ6yVkzCRxhRMsiRQnD1o= diff --git a/lambda/room/{room_id}/POST/main.go b/lambda/room/{room_id}/POST/main.go index 791ca3a..dcbdfc2 100644 --- a/lambda/room/{room_id}/POST/main.go +++ b/lambda/room/{room_id}/POST/main.go @@ -21,6 +21,7 @@ type Answer struct { type UserData struct { UserId string `json:"uid" dynamodbav:"user_id"` NickName string `json:"nickname" dynamodbav:"nickname"` + RoomName string `json:"roomname" dynamodbav:"room_name"` Answers []Answer `json:"answers" dynamodbav:"answers"` } @@ -47,6 +48,7 @@ func enterRoomHandler(ctx context.Context, event events.APIGatewayProxyRequest) userData.UserId = userId.String() userData.NickName = req.NickName userData.Answers = req.Answers + userData.RoomName = roomId // 書き込み処理 cfg, err := config.LoadDefaultConfig(ctx) @@ -83,26 +85,30 @@ func insertUserDataToCandleBackendUserTable(cfg aws.Config, ctx context.Context, tableName = t } - var dynamoValue []types.AttributeValue + var answers []types.AttributeValue for _, ans := range userData.Answers { - answerMap := map[string]types.AttributeValue{ + ansMap := map[string]types.AttributeValue{ "question_id": &types.AttributeValueMemberS{Value: ans.QuestionId}, "answer": &types.AttributeValueMemberBOOL{Value: ans.Answer}, } - dynamoValue = append(dynamoValue, &types.AttributeValueMemberM{Value: answerMap}) + answers = append(answers, &types.AttributeValueMemberM{Value: ansMap}) } - _, err := svc.PutItem(ctx, &dynamodb.PutItemInput{ + params := &dynamodb.PutItemInput{ TableName: aws.String(tableName), Item: map[string]types.AttributeValue{ - "user_id": &types.AttributeValueMemberS{Value: userData.UserId}, - "nickname": &types.AttributeValueMemberS{Value: userData.NickName}, - "answers": &types.AttributeValueMemberL{Value: dynamoValue}, - }, ConditionExpression: aws.String("attribute_not_exists(nickname,answers)"), - }) + "user_id": &types.AttributeValueMemberS{Value: userData.UserId}, + "nickname": &types.AttributeValueMemberS{Value: userData.NickName}, + "room_name": &types.AttributeValueMemberS{Value: userData.RoomName}, + "answers": &types.AttributeValueMemberL{Value: answers}, + }, + } + + _, err := svc.PutItem(ctx, params) if err != nil { return err } + return nil } From f2f0df8b0a27d7c291d1c2d6095937dadc82b0af Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Mon, 18 Dec 2023 11:30:48 +0900 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0?= =?UTF-8?q?=E3=81=AEtypo=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/room/{room_id}/POST/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/room/{room_id}/POST/main.go b/lambda/room/{room_id}/POST/main.go index dcbdfc2..b0700bc 100644 --- a/lambda/room/{room_id}/POST/main.go +++ b/lambda/room/{room_id}/POST/main.go @@ -81,7 +81,7 @@ func insertUserDataToCandleBackendUserTable(cfg aws.Config, ctx context.Context, svc := dynamodb.NewFromConfig(cfg) tableName := "CandleBackendUserTable" - if t, exists := os.LookupEnv("USER_ABLE_NAME"); exists { + if t, exists := os.LookupEnv("USER_TABLE_NAME"); exists { tableName = t } From 2af080e463e0cb4739b9ec2b90f1c2e9cea1492b Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Mon, 18 Dec 2023 11:33:32 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=E6=A7=8B=E9=80=A0=E4=BD=93=E3=81=AE?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=90=E3=81=AE=E5=91=BD=E5=90=8D=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda/room/{room_id}/POST/main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lambda/room/{room_id}/POST/main.go b/lambda/room/{room_id}/POST/main.go index b0700bc..11b31f5 100644 --- a/lambda/room/{room_id}/POST/main.go +++ b/lambda/room/{room_id}/POST/main.go @@ -15,13 +15,13 @@ import ( ) type Answer struct { - QuestionId string `json:"question_id" dynamodbav:"question_id"` + QuestionID string `json:"question_id" dynamodbav:"question_id"` Answer bool `json:"answer" dynamodbav:"answer"` } type UserData struct { - UserId string `json:"uid" dynamodbav:"user_id"` - NickName string `json:"nickname" dynamodbav:"nickname"` - RoomName string `json:"roomname" dynamodbav:"room_name"` + UserID string `json:"user_id" dynamodbav:"user_id"` + NickName string `json:"nickname" dynamodbav:"nickname"` + RoomID string `json:"room_id" dynamodbav:"room_id"` Answers []Answer `json:"answers" dynamodbav:"answers"` } @@ -45,10 +45,10 @@ func enterRoomHandler(ctx context.Context, event events.APIGatewayProxyRequest) var userData UserData userId := uuid.New() - userData.UserId = userId.String() + userData.UserID = userId.String() userData.NickName = req.NickName userData.Answers = req.Answers - userData.RoomName = roomId + userData.RoomID = roomId // 書き込み処理 cfg, err := config.LoadDefaultConfig(ctx) @@ -88,7 +88,7 @@ func insertUserDataToCandleBackendUserTable(cfg aws.Config, ctx context.Context, var answers []types.AttributeValue for _, ans := range userData.Answers { ansMap := map[string]types.AttributeValue{ - "question_id": &types.AttributeValueMemberS{Value: ans.QuestionId}, + "question_id": &types.AttributeValueMemberS{Value: ans.QuestionID}, "answer": &types.AttributeValueMemberBOOL{Value: ans.Answer}, } answers = append(answers, &types.AttributeValueMemberM{Value: ansMap}) @@ -97,9 +97,9 @@ func insertUserDataToCandleBackendUserTable(cfg aws.Config, ctx context.Context, params := &dynamodb.PutItemInput{ TableName: aws.String(tableName), Item: map[string]types.AttributeValue{ - "user_id": &types.AttributeValueMemberS{Value: userData.UserId}, + "user_id": &types.AttributeValueMemberS{Value: userData.UserID}, "nickname": &types.AttributeValueMemberS{Value: userData.NickName}, - "room_name": &types.AttributeValueMemberS{Value: userData.RoomName}, + "room_id": &types.AttributeValueMemberS{Value: userData.RoomID}, "answers": &types.AttributeValueMemberL{Value: answers}, }, } From 87c0d9988d69db8eff62a1fd5eee9615d73b2d83 Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Mon, 18 Dec 2023 11:51:25 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20=E9=96=93=E9=81=95=E3=81=88=E3=81=A6?= =?UTF-8?q?=E3=82=A2=E3=83=BC=E3=82=AD=E3=83=86=E3=82=AF=E3=83=81=E3=83=A3?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C=E3=81=AE=E3=83=96=E3=83=A9=E3=83=B3=E3=83=81?= =?UTF-8?q?=E3=82=92rebase=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E5=A4=89=E6=9B=B4=E7=AE=87=E6=89=80=E3=81=8C=E5=B0=91?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=9F=E3=82=81=E6=89=8B=E5=8B=95=E3=81=A7?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/candle-backend-stack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/candle-backend-stack.ts b/lib/candle-backend-stack.ts index 679c4bf..59a298a 100644 --- a/lib/candle-backend-stack.ts +++ b/lib/candle-backend-stack.ts @@ -46,7 +46,7 @@ export class CandleBackendStack extends cdk.Stack { 'bash', '-c', [ "export GOCACHE=/tmp/go-cache", "export GOPATH=/tmp/go-path", - "GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -tags lambda.norpc -o /asset-output/bootstrap main.go", + "CGO_ENABLED=0 GOOS=linux go build -tags lambda.norpc -o /asset-output/bootstrap main.go", ].join(" && "), ], }, @@ -63,7 +63,7 @@ export class CandleBackendStack extends cdk.Stack { environment: { TABLE_NAME: questionTable.tableName, }, - + }); questionTable.grantReadWriteData(questionsGETHandler); questions.addMethod('GET', new apigateway.LambdaIntegration(questionsGETHandler)); From 720477dd4b8938d29dfd5a44fb1d44f8cf4cfa4d Mon Sep 17 00:00:00 2001 From: GoRuGoo Date: Mon, 18 Dec 2023 11:53:54 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=E5=85=88=E3=81=BB=E3=81=A9=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88=E5=90=8C=E6=A7=98=E3=81=AB?= =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=A4=89=E6=9B=B4=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/candle-backend.ts | 7 ++++--- cdk.json | 2 +- lib/candle-backend-stack.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/candle-backend.ts b/bin/candle-backend.ts index 78e9016..9c0b8ee 100644 --- a/bin/candle-backend.ts +++ b/bin/candle-backend.ts @@ -18,7 +18,8 @@ new CandleBackendStack(app, 'CandleBackendStack', { // env: { account: '123456789012', region: 'us-east-1' }, /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ - synthesizer: new cdk.DefaultStackSynthesizer({ - qualifier: "candle", - }), + + synthesizer: new cdk.DefaultStackSynthesizer({ + qualifier: 'candle', + }), }); diff --git a/cdk.json b/cdk.json index 03207af..a08006f 100644 --- a/cdk.json +++ b/cdk.json @@ -56,6 +56,6 @@ "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true, - "@aws-cdk/core:bootstrapQualifier": "candle" + "@aws-cdk/core:bootstrapQualifier": "candle" } } diff --git a/lib/candle-backend-stack.ts b/lib/candle-backend-stack.ts index 59a298a..4ee13d5 100644 --- a/lib/candle-backend-stack.ts +++ b/lib/candle-backend-stack.ts @@ -63,7 +63,7 @@ export class CandleBackendStack extends cdk.Stack { environment: { TABLE_NAME: questionTable.tableName, }, - + }); questionTable.grantReadWriteData(questionsGETHandler); questions.addMethod('GET', new apigateway.LambdaIntegration(questionsGETHandler));