In this case, while these environment variables appear to be sensitive, they are ephemeral keys, uniquely issued to the Function as part of running within Lambda. Their associated actions and permissions have been reviewed, approved and are required to run the Function. There is no risk of any Twilio customer’s Function being accessed or modified by disclosure of these keys.
That said, we much appreciate the community raising potential concerns. If y’all ever see anything that looks like a vulnerability, we’d love for you to submit it to our Bug Bounty program: https://bugcrowd.com/twilio
Maybe they actually intend for people to be able to use all the functionality of Lambda, some of which (I guess) requires using the AWS access key?
Or are people naively assuming their own Lambda container is a reasonable sandbox for third-party code? If so, yikes.
Another take on this is that they're creating value for customers by shifting the reliability requirements from the customers themselves to AWS / lambda
... which I think is brilliant.
I feel like this new feature will make it super easy to work with Twilio. It's almost a no brainer.
But despite all that, I feel like setting everything up in one place would be a lot simpler.
Now if Twilio had a way to deploy serverless functions via git... that would be a clincher.
Also, a hell of a lot of work went into this feature. You can try setting this infrastructure up yourself if you think it will save you money. You already know they're using Lambda!
Sometimes systems that are secure with two parties become horribly insecure when you add a third. I don't know a lot about IAM but generally I'd be very cautious about using standard access control mechanisms to implement sandboxing while running the code "in your account", as often you find resources are made available to "the whole account" with no further access control settings, because the system designers didn't imagine customers running true third-party code.
That said Amazon has some pretty thorough access control features and I'm sure Twilio has looked into it and figured out something reasonable.
If you think about this product, you are paying for the service, so if you tried anything malicious, at worst you would do is impact yourself, and ultimately pick up a bill for your usage at the end of month, heh.
From what I can tell API gateway costs $3.50 a month per 1m calls, so unless they've negotiated some deal with AWS or something...
Edit: adding linebreaks...
2nd edit: Realized there were AWS access tokens in there. It's probably not a good idea for those to be exposed to the environment they're running this user generated code in. They should probably be wrapping these in vm.runInNewContext()