[英]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.