How to trigger GCP cloud function(private) from AWS SNS over http trigger

1.1k views Asked by At

I have cloud function in GCP which triggers when any object is received in s3 bucket using SNS notification. SNS has been configured in such a way, when any object comes in s3 bucket it notifies GCP cloud function about it using http trigger(https url). As of now Cloud function end point is public so that it could be triggered from anywhere even from web browser if someone has the url which is big security concern. Hence I would like to make it private and want it to be accessed only through AWS SNS but getting no idea how it could be done.

1

There are 1 answers

0
John Hanley On BEST ANSWER

You cannot prevent users from calling your HTTP endpoint as you must make the endpoint public in order for Amazon SNS to be able to call your endpoint. You can validate requests and reject requests (return 401 Unauthorized) that you do not want to process.

There are several methods to validate requests. I am listing the methods from least secure to most secure (also easiest to hardest to implement).

Check the x-amz-sns-topic-arn or x-amz-sns-subscription-arn for values you expect in the HTTP POST request headers.

Configure SNS to use Basic Authentication using a username and password. Verify both values.

Verify the SNS notification signature. This method requires downloading the Amazon certificate and validating the signature on each request.

Using Amazon SNS for system-to-system messaging with an HTTP/s endpoint as a subscriber