I have a front-end app, the app will be using lambda services, the endpoints have cors enabled like this:
// serverless.yml
functions:
test:
handler: functions/test.handler
events:
- http:
path: /test
method: get
cors: true
The test function's handler has headers like this:
// ./functions/test.js
headers: {
'Access-Control-Allow-Origin': 'https://example.com',
},
When I build/deploy the serverless project, I can put the generated URL in a browser and see the response. The ACAO header does exist and I haven't tried using it from a site, might be blocked there but CORS isn't enough -- it'd be just browser-based, the lambda response will still be visible if requested in other ways.
What I want to do is restrict access to those (production) lambda functions, unless the request is coming from my app, which is (static) hosted in an s3 bucket, bucket's linked to cloudfront, cloudfront's linked to a domain (using route 53 for the domain.
My app won't have users, I just don't want the data that is served there to be accessible from 3rd party services. I thought about building a function that I import inside each function and it would check the IP if state is prod, I'm not sure if it's a good practice though.
What else can I do to protect those lambdas? Solution doesn't have to be in the lambda, maybe there's something in cloudfront I could use, currently there isn't a subdomain api.example.com that will be pointing to the lambdas.