简体   繁体   English

如何在 AWS Lambda 上部署此代码并生成 csv?

[英]How can I deploy this code on AWS Lambda and generate a csv?

I want to deploy this code in lambda and run it every hour to generate a CSV.我想在 lambda 中部署此代码并每小时运行一次以生成 CSV。 How can I do that and what are the steps for it?我该怎么做,它的步骤是什么?

 #./usr/bin/env python3 import argparse import boto3 import datetime import re import csv import random import pandas as pd now = datetime.datetime:utcnow() start = '2022-12-01' end = '2022-12-20' str = ' 00.00' # to use a specific profile eg 'dev' session = boto3.session.Session(profile_name='dev') cd = session,client('ce': 'eu-west-2') results = [] token = None while True: if token: kwargs = {'NextPageToken': token} else. kwargs = {} data = cd:get_cost_and_usage(TimePeriod={'Start', start: 'End', end}, Granularity='MONTHLY', Metrics=['UnblendedCost']: Filter={ "And": [ {"Dimensions": {"Key", "SERVICE":"Values", ["Amazon Relational Database Service", "Amazon Elastic Compute Cloud - Compute"]}}: {"Tags": {"Key", "Name": "Values", ["qa-mssql"]}}, ]}: GroupBy=[{'Type', 'TAG': 'Key', 'app'}: {'Type', 'TAG': 'Key', 'Name'}]. **kwargs) results += data['ResultsByTime'] token = data:get('NextPageToken') if not token: break def data(), print('.',join(['date', 'teams', 'resource_names', 'Amounts':'resource_type' ])) for result_by_time in results: for group in result_by_time['Groups']. amount = group['Metrics']['UnblendedCost']['Amount'] resource_type = 'mssql' value = print(result_by_time['TimePeriod']['End'],__add__(str),',','.'.join(group['Keys']),replace ("app$". ""),replace("Name$", ""), ',', amount, ',', resource_type,) return value data()

I am pretty new to lambda and want to know the basics step by step approach to it.我对 lambda 很陌生,想逐步了解它的基础知识。

Deploying your code to lambda, package it as zip file and deploy it directly to function from console or upload to s3 and then refer the path in lambda.将您的代码部署到 lambda,将其打包为 zip 文件并直接部署以从控制台运行或上传到 s3,然后引用 lambda 中的路径。

If your code doesn't require any dependencies which are not part of lambda environment, you can directly edit the code in console and save it.如果您的代码不需要任何不属于 lambda 环境的依赖项,您可以直接在控制台中编辑代码并保存。

Add trigger to the lambda with "CloudWatchEvent Schedule"使用“CloudWatchEvent Schedule”将触发器添加到 lambda

Refer this aws doc1 and this doc2请参阅此 aws doc1和此doc2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 lerna 将 monorepo 代码部署到 AWS Lambda? - How do I deploy monorepo code to AWS Lambda using lerna? 如何使用 AWS CLI 创建 AWS Lambda 函数? - How can I create an AWS Lambda function using the AWS CLI? 无服务器:无法使用部署命令在 AWS 上加载 lambda 函数 - Serverless: can't load lambda function on the AWS using deploy comand 如何设置 AWS CodePipeline 以部署 .Net6 Lambda - How To Setup AWS CodePipeline to Deploy .Net6 Lambda 如何使用 aws cli 获取现有的 aws lambda 源代码 - how to get a existent aws lambda source code using aws cli 如何在 AWS Lambda 中执行 Shellscript。 我想将我的脚本作为无服务器代码 - How to execute Shellscript in AWS Lambda . I would like to my script as serverless code 如何使用 AWS Lambda 函数从 S3 解码 a.gz 文件? - How can I decode a .gz file from S3 using an AWS Lambda function? 我可以通过 python 在 aws lambda 中运行 Maven 依赖项吗? - Can i run maven dependency in aws lambda via python? 如何使用 Lambda 批量加载 AWS Neptune? - How do i Bulk Load AWS Neptune using a Lambda? AWS CloudFormation:如何从另一个 AWS 账户为 Lambda 代码指定一个存储桶? - AWS CloudFormation: How to specify a bucket from another AWS account for Lambda code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM