我有一个Django视图来创建一种AWS包(包含帐户和新的vpc创建),我试图调用它之间的lambda函数,它将删除新创建的帐户中的默认vpc。这是我的片段:
def createlab(request):
if request.method == 'POST':
lab_name = request.POST.get('labname')
cidr = request.POST.get('cidr')
bill = request.POST.get('budget')
email = request.POST.get('email')
#CREATE ACCOUNT
org = boto3.client('organizations')
acc = org.create_account(
Email=email,
AccountName=lab_name,
IamUserAccessToBilling='ALLOW'
)
time.sleep(35)
cid = acc['CreateAccountStatus']['Id']
#GET ACCOUNT DETAILS
status = org.describe_create_account_status(
CreateAccountRequestId=cid
)
print(status)
time.sleep(17)
while True:
status = org.describe_create_account_status(CreateAccountRequestId=cid)
try:
accid = status['CreateAccountStatus']['AccountId']
break
except KeyError:
time.sleep(40)
accid = status['CreateAccountStatus']['State']
#CREATE VPC
session =
boto3.Session
(aws_access_key_id=acc_key,
aws_secret_access_key=sec_key,aws_session_token=token)
ec2 = session.resource('ec2',region_name=region_ec2_sub)
vpc = ec2.create_vpc(CidrBlock=cidr)
id = vpc.id
#DELETE DEFAULT VPC
client = boto3.client('lambda',region_name='us-west-2')
deletevpc=
client.invoke(FunctionName='default_vpc',
InvocationType='RequestResponse')
print (deletevpc)
我已经包含了一部分我的观点功能。我最后添加了#DELETE DEFAULT VPC片段。 lambda函数没有被执行。我在这里做错了什么?