如何解决cloudformation堆栈部署完成后返回FilesystemID
我正在尝试使用 boto3 在 lambda 中使用 cloudformation 模板创建 efs 文件系统。并且有兴趣使用describe_stack从堆栈返回作为Filesystemid的输出。但是我得到空值作为回报。请指出我哪里出错了。
错误是:
Response
null
代码是:
import boto3
import time
import json
import botocore
datetime = time.strftime("%Y%m%d%H%M%s")
stackname = 'My-EFS'
region = "ap-south-1"
client = boto3.client('cloudformation')
s = boto3.Session(region_name=region)
def lambda_handler(event,context):
response = client.create_stack(
StackName= stackname,TemplateURL='https://cloudnaeem.s3.amazonaws.com/efs.yaml',)
waiter = client.get_waiter('stack_create_complete')
res = waiter.wait(
StackName=stackname,)
stack = client.describe_stacks(StackName=stackname)
FileSystem_id=None
for v in stack["Stacks"][0]["Outputs"]:
if v["OutputKey"] == "FileSystemId":
FileSystem_id = v["OutputValue"]
return FileSystem_id
模板输出为:
Outputs:
EFS:
Description: The created EFS
Value: !Ref EFSFileSystem
解决方法
您的输出名为 EFS
,但您正在寻找 FileSystemId
。您的代码应该是这样的:
for v in stack["Stacks"][0]["Outputs"]:
if v["OutputKey"] == "EFS":
FileSystem_id = v["OutputValue"]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。