【问题标题】:Using Lambda to Upload to S3使用 Lambda 上传到 S3
【发布时间】:2020-09-04 21:47:24
【问题描述】:

我创建了一个 lambda 函数,它从 S3 下载数据,然后执行合并,然后将其重新上传回 S3,但我已经得到了这个

错误{ “errorMessage”:“2020-05-18T23:23:27.556Z 37233f48-18ea-43eb-9030-3e8a2bf62048 任务在 3.00 秒后超时” }

当我删除 45 到 58 之间的线时,它工作得很好

https://ideone.com/RvOmPS

将熊猫导入为 pd 将 numpy 导入为 np 进口时间 从 io 导入 StringIO # python3; python2:字节IO 导入 boto3 导入 s3fs from botocore.exceptions 导入 NoCredentialsError

def lambda_handler(事件,上下文):

# Dataset 1
# loading the data
df1 = pd.read_csv("https://i...content-available-to-author-only...s.com/Minimum+Wage+Data.csv",encoding= 'unicode_escape')

# Renaming the columns.
df1.rename(columns={'High.Value': 'min_wage_by_law', 'Low.Value': 'min_wage_real'}, inplace=True)

# Removing all unneeded values.
df1 = df1.drop(['Table_Data','Footnote','High.2018','Low.2018'], axis=1)
df1 = df1.loc[df1['Year']>1969].copy()

# ---------------------------------

# Dataset 2
# Loading from the debt S3 bucket
df2 = pd.read_csv("https://i...content-available-to-author-only...s.com/USGS_Final_File.csv") 

#Filtering getting the range in between 1969 and 2018.
df2 = df2.loc[df2['Year']>1969].copy()
df2 = df2.loc[df2['Year']<2018].copy()
df2.rename(columns={'Real State Growth %': 'Real State Growth','Population (million)':'Population Mil'}, inplace=True)

# Cleaning the data
df2['State Debt'] = df2['State Debt'].str.replace(',', '')
df2['Local Debt'] = df2['Local Debt'].str.replace(',', '')
df2["State and Local Debt"] = df2["State and Local Debt"].str.replace(',', '')
df2["Gross State Product"] = df2["Gross State Product"].str.replace(',', '')

# Cast to Floating
df2[["State Debt","Local Debt","State and Local Debt","Gross State Product"]] = df2[[ "State Debt","Local Debt","State and Local Debt","Gross State Product"]].apply(pd.to_numeric)

# --------------------------------------------
# Merge the data through an inner join.
full = pd.merge(df1,df2,on=['State','Year'])
#--------------------------------------------
filename = '/tmp/'#specify location of s3:/{my-bucket}/
file= 'debt_and_wage' #name of file
datetime = time.strftime("%Y%m%d%H%M%S") #timestamp
filenames3 = "%s%s%s.csv"%(filename,file,datetime) #name of the filepath and csv file

full.to_csv(filenames3, header = True)

## Saving it on AWS

s3 = boto3.resource('s3',aws_access_key_id='accesskeycantshare',aws_secret_access_key= 'key')

s3.meta.client.upload_file(filenames3, 'information-arch',file+datetime+'.csv')

【问题讨论】:

    标签: python amazon-web-services amazon-s3 amazon-ec2 aws-lambda


    【解决方案1】:

    您的默认 lambda execution timeout3 秒。请将其增加到适合您的任务:

    超时 – Lambda 允许函数在停止之前运行的时间量。默认值为 3 秒。允许的最大值为 900 秒

    【讨论】:

      【解决方案2】:

      您应该增加 lambda 函数的超时时间。新创建函数的默认行为是在 3 秒后终止。

      【讨论】:

        【解决方案3】:

        谢谢大家的帮助,只是做了什么增加了超时,它工作得很好,我通过here做到了

        【讨论】:

        • 很高兴它成功了。但是4秒可以吗?它似乎处于您的功能需要的边界?也许为了安全起见,让它到 10 秒?
        【解决方案4】:

        如果作业大小很大,您可以尝试增加函数的内存。 现在增加函数的超时时间。

        【讨论】:

          猜你喜欢
          • 2018-07-12
          • 2021-08-22
          • 2020-04-02
          • 1970-01-01
          • 1970-01-01
          • 2021-02-28
          • 1970-01-01
          • 1970-01-01
          • 2017-09-04
          相关资源
          最近更新 更多