Hi
I need to design an image resizing service that is able to resize the image on the fly.
So the flow is as follow:
- Users send the request for image AAA.png in size 400*400 to S3 bucket
- If object isn’t there, S3 will then forward the request to lambda
- Lambda fetches the original image AAA.png from bucket and resize it, put it back into s3 as AAA_400_400.png
- Once lambda has done its job, the API Gateway permanently redirects the user to the AAA_400_400.png stored in S3.
The place I get stuck is S3 redirect the request to lambda
Wonder how I can reference the apig hostname inside my s3 resource.
See below
Thanks
bill
2
You can reference it directly { "Ref" : "ApiGatewayRestApi" }
.
See this question I asked before. [Fixed] How do i get/reference api gateway restapi id in serverless.yml?
This is the way to get api gateway id. You need use it and add more path (region, etc) to form the full api gateway url
Thanks mate for pointing me at the correct path.
One more quick question, it appears that ApiGatewayRestApi corresponds to AWS::ApiGateway::RestApi and in aws docs, it says
When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the RestApi ID, such as a1bcdef2gh.
So I assume ApiGatewayRestApi is the logical id? But I could not find ApiGatewayRestApi anywhere in serverless docs.
buggy
4
I wrote something on this a year ago How to I get my API Gateway URL with the Serverless Framework. The short version is:
{ "Fn::Join" : ["", [ "https://", { "Ref" : "ApiGatewayRestApi" }, ".execute-api.${self:custom.region}.amazonaws.com/${self:custom.stage}" ] ] }
1 Like
Yup. I’ve read your post. Really helpful! Thanks