[英]How to run lambda with CLI, orLambda python command that can call the command
我正在嘗試創建一個 AWS Lambda function 創建一個文件,然后將其上傳到 S3。
AWS CLI 命令將是:
aws ec2 describe-network-interfaces --output table > report.csv
aws s3 cp report.csv s3://testec2lambd
無論如何,我可以在我的 Lambda function 中使用 AWS CLI 嗎?
或者,我如何在 function 中將其編寫為 python 腳本?
無需從 AWS Lambda function 調用 AWS CLI,您可以在 Lambda ZC1C425268E683894F1C157A 中執行所有操作。 例如:
import boto3
import pprint
# Describe Network Interfaces
ec2_client = boto3.client('ec2')
response = ec2_client.describe_network_interfaces()
# Save it to a local file
pretty_print_json = pprint.pformat(response).replace("'", '"')
with open('/tmp/output_file', 'w') as f:
f.write(pretty_print_json)
# Upload file to S3
s3_client = boto3.client('s3')
s3_client.upload_file('/tmp/output_file', 'mybucket', 'mykey')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.