Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apigw-lambda-rekognition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ Important: this application uses various AWS services and there are costs associ

1. Make a POST request to the API using the following cURL command:

```
curl --location 'https://<api-id>.execute-api.<region>.amazonaws.com/dev/generate-presigned-url' --header 'Content-Type: text/plain' --data '{"object_name": "image.png", "content_type": "image/png"}'
```

Note: Replace 'api-id' with the generated API ID from Terraform, 'region' with the region where the API is deployed (refer to the Terraform Outputs section) 'object_name' with your desired name for the S3 object and 'content_type' with the content type of the image, for ex, png or jpeg

1. Get the pre-signed URL from the previous step and use the following cURL command to upload the object in S3:

curl -v --location --request PUT '<presigned-url>' --header 'Content-Type: image/png' --data '<path-of-the-object>.png'
```
curl -v --location --request PUT '<presigned-url>' --header 'Content-Type: image/png' --data-binary @image.png
```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: --data '<path-of-the-object>.png' command upload not image file. We should use --data-binary option. I updated it and works goodπŸ˜€


Note: Replace 'presigned-url' with pre-signed URL generated in the previous step. 'Content-Type' should match the content type used to generate the pre-signed URL in the previous step. Make sure you are passing the correct path of the object in the --data parameter.

Expand Down Expand Up @@ -96,4 +100,4 @@ Important: this application uses various AWS services and there are costs associ
----
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
SPDX-License-Identifier: MIT-0
12 changes: 10 additions & 2 deletions apigw-lambda-rekognition/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ resource "aws_s3_bucket_notification" "s3_bucket_notification" {
lambda_function_arn = aws_lambda_function.process_s3_event.arn
events = ["s3:ObjectCreated:*"]
}

depends_on = [aws_lambda_permission.allow_s3]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

β•·
β”‚ Error: creating S3 Bucket (xxxxx-s3-upload) Notification: operation error S3: PutBucketNotificationConfiguration, https response error StatusCode: 400, RequestID: ZRGV6RJWYEZQXGDX, HostID: hB9Ze5FjoPl01sqeI3/PGRae4EM5YzhB/dKN1oI5V8kUP5c2t1zvsWwsGhHU8D94FtmL2uETUi8=, api error InvalidArgument: Unable to validate the following destination configurations
β”‚ 
β”‚   with aws_s3_bucket_notification.s3_bucket_notification,
β”‚   on main.tf line 101, in resource "aws_s3_bucket_notification" "s3_bucket_notification":
β”‚  101: resource "aws_s3_bucket_notification" "s3_bucket_notification" {
β”‚ 
β•΅

}
resource "aws_lambda_permission" "allow_s3" {
statement_id = "${lower(var.prefix)}-allow-s3-invoke-lambda"
Expand Down Expand Up @@ -145,8 +147,14 @@ resource "aws_lambda_permission" "allow_api_gateway" {
resource "aws_api_gateway_deployment" "deployment" {
depends_on = [aws_api_gateway_integration.integration]
rest_api_id = aws_api_gateway_rest_api.api.id
stage_name = "dev"
}

resource "aws_api_gateway_stage" "stage" {
deployment_id = aws_api_gateway_deployment.deployment.id
rest_api_id = aws_api_gateway_rest_api.api.id
stage_name = "dev"
}

output "api_id" {
description = "The ID of the API Gateway REST API"
value = aws_api_gateway_rest_api.api.id
Expand Down Expand Up @@ -178,4 +186,4 @@ output "lambda_generate_presigned_url_log_group" {
output "lambda_process_s3_event_log_group" {
description = "The name of the CloudWatch log group for the process_s3_event Lambda function"
value = aws_cloudwatch_log_group.lambda_log_group[1].name
}
}