简体   繁体   English

无服务器框架中的参考现有Cloudformation堆栈输出

[英]Reference Existing Cloudformation Stack Outputs in Serverless Framework

We're evaluating whether to use Serverless for some of our new AWS application infrastructure. 我们正在评估是否对某些新的AWS应用程序基础架构使用Serverless We heavily use Cloudformation (deployed by Ansible), so we would need to be able to cleanly reference the outputs of existing Cloudformation stacks -- one immediate example would be for getting the subnet IDs of our existing AWS network infrastructure for use by a lambda function. 我们大量使用Cloudformation(由Ansible部署),因此我们需要能够干净地引用现有Cloudformation堆栈的输出-一个直接的例子是获取现有AWS网络基础设施的子网ID以供lambda函数使用。

After a lot of browsing, I haven't seen an out-of-the-box way to do this. 经过大量的浏览之后,我还没有看到一种开箱即用的方式来做到这一点。 Our existing Cloudformation stacks are named such that if I could just key in the name of the stack and the desired output variable, I could reliably get the desired outputs across various environments. 我们现有的Cloudformation堆栈的命名方式是,如果我只要键入堆栈名称和所需的输出变量,就可以在各种环境中可靠地获取所需的输出。 One possible solution I see is to pull the variables using aws cli and pass them as environment variables to serverless, but I would like a cleaner way if possible. 我看到的一种可能的解决方案是使用aws cli拉取变量,并将其作为环境变量传递给无服务器,但是如果可能的话,我希望有一种更清洁的方法。

如果无服务器框架允许您在CloudFormation模板中使用内部函数 ,则可以通过从一个堆栈导出堆栈输出值 (使用Outputs部分中的Exports属性)并使用Fn::ImportValue在CloudFormation模板中创建跨堆栈引用。 Fn::ImportValue内部函数在另一个堆栈中以引用导出的值。

The easiest way I can think to handle your example case is to have the lambda use boto3 to call boto3.client('cloudformation', region_name=*specified region*).describe_stacks(StackName=*specified stack*)['Stacks'] . 我认为处理示例的最简单方法是让lambda使用boto3调用boto3.client('cloudformation', region_name=*specified region*).describe_stacks(StackName=*specified stack*)['Stacks'] This list contains all stacks that match the StackName specified, if all of your network infrastructure shares a subset of their names, you can list all of them by specifying the StackName to that substring. 此列表包含与指定的StackName匹配的所有堆栈,如果所有网络基础结构共享其名称的子集,则可以通过为该子字符串指定StackName来列出所有StackName Each Stack object contains an 'Outputs' block. 每个堆栈对象都包含一个'Outputs'块。 See here . 这里

If you'd like to expose this for easy use from anywhere, you can attach an API Gateway GET method to the lambda and expose it to an HTML form. 如果您想在任何地方公开它以便于使用,可以将API Gateway GET方法附加到lambda并将其公开为HTML表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM