我正在尝试使用cloudformation模板在lambda内使用boto3创建efs文件系统。并且有兴趣使用descripbe_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"]