【问题标题】:Return FilesystemID after cloudformation stack deployment completecloudformation 堆栈部署完成后返回 FilesystemID
【发布时间】:2021-05-27 18:52:50
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 你的模板输出是什么?
  • 模板输出已编辑,请检查
  • @Marcin,请检查

标签: amazon-web-services aws-lambda amazon-cloudformation amazon-efs


【解决方案1】:

您的输出名为EFS,但您正在寻找FileSystemId。你的代码应该是这样的:

    for v in stack["Stacks"][0]["Outputs"]:
        if v["OutputKey"] == "EFS":
            FileSystem_id = v["OutputValue"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-01
    • 2019-06-27
    • 2013-08-25
    • 2023-03-24
    • 2017-02-21
    • 2018-07-31
    • 2018-08-24
    • 1970-01-01
    相关资源
    最近更新 更多