我試圖隨時部署我的lambda函數,而我的s3存儲區包含它的更新。如何使用lamda將s3中的最新代碼部署到lamda函數
如果我知道我有一個桶中,我可以簡單地使用雲的形成自動lambda函數的創建和部署
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation CloudWatch Log Janitor Demo Stack",
"Resources": {
"TestLamdaRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}]
},
"Path": "/"
}
},
"EbsBackupExecutionPolicy": {
"DependsOn": [
"TestLamdaRole"
],
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "hamedlamdapolicytest",
"Roles": [{
"Ref": "TestLamdaRole"
}],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"logs:*"
],
"Resource": [
"arn:aws:lambda:us-east-1:1111111111111:function:*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:Describe*"
],
"Resource": [
"*"
]
}
]
}
}
},
"LambdaFuction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "lambda-dep-test",
"S3Key": "index.zip"
},
"Role": {
"Fn::GetAtt": [
"TestLamdaRole",
"Arn"
]
},
"Timeout": 60,
"Handler": "lambda_function.handler",
"Runtime": "nodejs6.10",
"MemorySize": 128,
"FunctionName": "stg1-test"
}
}
}
}
了最新的zip拉姆達代碼,但問題是,只要我運行上面的lambda代碼,然後每當用戶把某物放入桶中時,最新的代碼不會自動部署。我知道這與lambda有關,但我迷路了,我不知道使用哪種方法以及從哪裏開始。你能說清楚這一點嗎?
有沒有簡單的方法來實現這一點。在S3中創建一個事件。無論何時添加新文件,該事件都會觸發不同的Lambda函數,它將更新原始函數(在這種情況下爲:stg1-test) –