Is it possible to retrieve existing resource identifiers within AWS SAM?

766 Views Asked by At

I have several services split up where serveral of these services are a lambda + api gateway which I decided to use the Serverless Application Model (SAM) tool that AWS provides so I can make use of local start-api while I am working locally on these services.

However, my main infrastructure is not written within SAM, and instead is written in Terraform. I know that if I wrote directly in SAM or Cloudformation my infrastructure would be built as a stack which would allow me to reference resources within the service's SAM template so that I can build those services making use of resource properties I wish to use. Is there a way within the SAM template to retrieve resource parameters (that already exist) for example subnet_id's, vpc_names ect?

The solution I have at the moment is to use the CLI to retrieve the properties I wish and pass them into SAM template as variables, is there a more elegant solution?

1

There are 1 best solutions below

0
On

I don't think so. This is probably the best option given you insist on using this combination of technologies. You could of course switch to a unified tech stack, i. e. Terraform OR CloudFormation. I am in the same situation by the way and my approach is exactly the one you have described. I have negotiated an API written in Terraform and whenever I need to use the infrastructure resources I am parsing out the names out of Json outputs and forwarding them to CDK or CloudFormation via command line parameters.