Skip to content

Commit

Permalink
テーブルの環境変数を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-osho-san committed Jan 1, 2025
1 parent 491e3c2 commit 84dff2d
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/backend/lambda/get_diary_data/get_diary_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def get_image(flower_id: str) -> Optional[str]:
except ClientError as e:
if e.response["Error"].get("Code") == "NoSuchKey":
logger.info(f"image not found: {s3_key}")
return None
logger.error(f"S3エラー: {e.response['Error']['Message']}")
raise
return ""


def get_title(user_id: str, date: str) -> Optional[str]:
Expand Down Expand Up @@ -149,10 +147,10 @@ def get_body(user_id: str, date: str) -> Optional[str]:
Returns:
Optional[str]: 本文またはNone。
"""
diary_table_name = os.getenv("TABLE_NAME")
diary_table_name = os.getenv("GENERATIVE_AI_TABLE_NAME")
if not diary_table_name:
logger.error("TABLE_NAME環境変数が設定されていません。")
raise ValueError("TABLE_NAME環境変数が設定されていません。")
logger.error("TABLE_NAME is not defined")
raise ValueError("TABLE_NAME is not defined")

diary_table = dynamodb.Table(diary_table_name)

Expand Down
6 changes: 6 additions & 0 deletions src/backend/lib/constructs/diary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,11 @@ export class Diary extends Construct {
props.generativeAiTable.grantReadData(getDiaryDataFunction)
props.flowerBucket.grantRead(getDiaryDataFunction)
props.table.grantReadData(getDiaryDataFunction)

const diaryDataApi = props.api.root.addResource('data')

diaryDataApi.addMethod('GET', new apigateway.LambdaIntegration(getDiaryDataFunction), {
authorizer: props.cognitoAuthorizer,
})
}
}
142 changes: 140 additions & 2 deletions src/backend/test/__snapshots__/snapshot.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,13 @@ exports[`Snapshot test 1`] = `
"Type": "AWS::IAM::Role",
"UpdateReplacePolicy": "Delete",
},
"ApiDiaryApiDeploymentCA0DCBF5ddc2bf13dbc3d7fbb845a336b665119f": {
"ApiDiaryApiDeploymentCA0DCBF5b35b07922434a278bec4b7d5379f45fe": {
"DependsOn": [
"ApiDiaryApibouquetGET7AC93032",
"ApiDiaryApibouquetPOST2DEB7999",
"ApiDiaryApibouquet8BAEBF58",
"ApiDiaryApidataGET0A09C29A",
"ApiDiaryApidataA4E0EFBE",
"ApiDiaryApidiaryDELETE81EA9C37",
"ApiDiaryApidiaryGET9A212B54",
"ApiDiaryApidiaryOPTIONS118FD5D0",
Expand Down Expand Up @@ -381,7 +383,7 @@ exports[`Snapshot test 1`] = `
"Format": "{"requestId":"$context.requestId","ip":"$context.identity.sourceIp","user":"$context.identity.user","caller":"$context.identity.caller","requestTime":"$context.requestTime","httpMethod":"$context.httpMethod","resourcePath":"$context.resourcePath","status":"$context.status","protocol":"$context.protocol","responseLength":"$context.responseLength"}",
},
"DeploymentId": {
"Ref": "ApiDiaryApiDeploymentCA0DCBF5ddc2bf13dbc3d7fbb845a336b665119f",
"Ref": "ApiDiaryApiDeploymentCA0DCBF5b35b07922434a278bec4b7d5379f45fe",
},
"MethodSettings": [
{
Expand Down Expand Up @@ -671,6 +673,142 @@ exports[`Snapshot test 1`] = `
},
"Type": "AWS::Lambda::Permission",
},
"ApiDiaryApidataA4E0EFBE": {
"Properties": {
"ParentId": {
"Fn::GetAtt": [
"ApiDiaryApi1E03348A",
"RootResourceId",
],
},
"PathPart": "data",
"RestApiId": {
"Ref": "ApiDiaryApi1E03348A",
},
},
"Type": "AWS::ApiGateway::Resource",
},
"ApiDiaryApidataGET0A09C29A": {
"Properties": {
"AuthorizationType": "COGNITO_USER_POOLS",
"AuthorizerId": {
"Ref": "ApiCognitoAuthorizer23B91BA2",
},
"HttpMethod": "GET",
"Integration": {
"IntegrationHttpMethod": "POST",
"Type": "AWS_PROXY",
"Uri": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition",
},
":apigateway:",
{
"Ref": "AWS::Region",
},
":lambda:path/2015-03-31/functions/",
{
"Fn::GetAtt": [
"DiarygetDiaryDataFunctionAAA49ECF",
"Arn",
],
},
"/invocations",
],
],
},
},
"ResourceId": {
"Ref": "ApiDiaryApidataA4E0EFBE",
},
"RestApiId": {
"Ref": "ApiDiaryApi1E03348A",
},
},
"Type": "AWS::ApiGateway::Method",
},
"ApiDiaryApidataGETApiPermissionCdkSampleStackApiDiaryApi4AB3EF3AGETdata3D3C2AA4": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"DiarygetDiaryDataFunctionAAA49ECF",
"Arn",
],
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition",
},
":execute-api:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":",
{
"Ref": "ApiDiaryApi1E03348A",
},
"/",
{
"Ref": "ApiDiaryApiDeploymentStageprodD9912276",
},
"/GET/data",
],
],
},
},
"Type": "AWS::Lambda::Permission",
},
"ApiDiaryApidataGETApiPermissionTestCdkSampleStackApiDiaryApi4AB3EF3AGETdata96E49F5D": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"DiarygetDiaryDataFunctionAAA49ECF",
"Arn",
],
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition",
},
":execute-api:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":",
{
"Ref": "ApiDiaryApi1E03348A",
},
"/test-invoke-stage/GET/data",
],
],
},
},
"Type": "AWS::Lambda::Permission",
},
"ApiDiaryApidiary4B91FACA": {
"Properties": {
"ParentId": {
Expand Down

0 comments on commit 84dff2d

Please sign in to comment.