i am trying to create efs filesystem using cloudformation template inside lambda using boto3. And interested to return output as Filesystemid from stack using describe_stack. however i am getting null values in return. please suggest where i am making mistake.
error is:
Response
null
Code is:
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
template output is :
Outputs:
EFS:
Description: The created EFS
Value: !Ref EFSFileSystem
Your output is called EFS
but you are looking for FileSystemId
. Your code should be thus:
for v in stack["Stacks"][0]["Outputs"]:
if v["OutputKey"] == "EFS":
FileSystem_id = v["OutputValue"]