简体   繁体   English

AWS lambda ResourceConflictException 部署

[英]AWS lambda ResourceConflictException on deployment

We have several lambda functions, and I've automated code deployment using the gradle-aws-plugin-reboot plugin.我们有几个 lambda 函数,我已经使用gradle-aws-plugin-reboot插件自动部署代码。

It works great on all but one lambda functions.它适用于除一个lambda 函数之外的所有函数。 On that particular one, I'm getting this error:在那个特定的那个上,我收到了这个错误:

com.amazonaws.services.lambda.model.ResourceConflictException: The operation cannot be performed at this time. An update is in progress for resource: arn:aws:lambda:*redacted*:the-lambda-that-fails (Service: AWSLambda; Status Code: 409; Error Code: ResourceConflictException; Request ID: 8fef505a-587c-4e77-a257-182d6eecadd0; Proxy: null)

There's an additional caveat to that error, though: It only happens on Jenkins.不过,该错误还有一个额外的警告:它只发生在 Jenkins 上。 Running the deployment task from my local machine works.从我的本地机器运行部署任务是可行的。 I can kind of reproduce the issue locally by spamming deployments in rapid succession, in which case every second one fails.我可以通过快速连续地发送垃圾邮件部署在本地重现该问题,在这种情况下,每秒都会失败。 Which is understandable, considering the error message.考虑到错误消息,这是可以理解的。

An interesting thing about this is, though, that while it fails with the same error, it does not fail at the same point as jenkins does.不过,有趣的是,虽然它因相同的错误而失败,但它不会像 jenkins 那样在同一点失败。 When I do that locally, it fails when deploying the environment, on jenkins it always fails when deploying the code.当我在本地执行此操作时,它在部署环境时失败,在 jenkins 上它在部署代码时总是失败。 I'm not sure which one the plugin does first, though.不过,我不确定插件先执行哪一个。 Also, it doesn't quite always fail on jenkins.此外,它并不总是在詹金斯身上失败。 There are rare instances when even the deployment of this lambda succeeds.很少有这种 lambda 部署成功的情况。 There are no instances of any of the other ones failing, though.不过,没有任何其他失败的例子。

I am aware of the new lambda states feature , and that it can potentially produce this error.我知道新的lambda 状态功能,它可能会产生此错误。 However, since all the other lambdas work, which are using the same code in both build.gradle as well as the jenkinsfile, it seems rather unlikely that this would be my issue.但是,由于所有其他 lambda 都可以工作,它们在 build.gradle 和 jenkinsfile 中都使用相同的代码,所以这似乎不太可能成为我的问题。

Here's what the deployment task in gradle looks like:下面是 gradle 中的部署任务:

   register<jp.classmethod.aws.reboot.gradle.lambda.AWSLambdaMigrateFunctionTask>("deploy") {

        // Create the environment variables from the gradle property configuration.
        // users and passwords should be stored in the system properties file, not the projects!
        val (environmentProperties, function) = if (branch == "master") {
            val webcamServicePutterProd: String by project
            val webcamServicePutterProdPwd: String by project
            mapLambdaProperties("deployProd_", webcamServicePutterProd, webcamServicePutterProdPwd) to
                    "lambda-function-name-prod"
        } else {
            val webcamServicePutterDev: String by project
            val webcamServicePutterDevPwd: String by project
            mapLambdaProperties("deployDev_", webcamServicePutterDev, webcamServicePutterDevPwd) to
                    "lambda-function-name-dev"
        }

        val jarFile = File("build/libs").walk().first { it.name.endsWith("-all.jar") }
        functionName = function
        zipFile = jarFile
        handler = "webcam.yellow.sqs.lambda.WebcamWorker::handleRequest"
        publish = true
        environment = environmentProperties
    }

As mentioned, this is pretty much identical in all the lambdas, apart from properties, obviously.如前所述,除了属性之外,这在所有 lambda 中几乎是相同的。 Properties can't really be the issue either though, since they're the same in my local environment and on jenkins.不过,属性也不是真正的问题,因为它们在我的本地环境和詹金斯上是相同的。

The deployment execution in the jenkinsfile is pretty unspectacular. jenkinsfile 中的部署执行非常不引人注目。 It first uploads the jar to S3 for archival, then executes the gradle task for deploying the lambda.它首先将 jar 上传到 S3 进行存档,然后执行部署 lambda 的 gradle 任务。 Just to be sure, I tried without the S3 upload just in case that might have some obscure connection, but that didn't help either.可以肯定的是,我尝试不使用 S3 上传以防万一可能有一些模糊的连接,但这也无济于事。

        stage('Deploy artifact') {
            when {
                equals expected: 'true', actual: deployArtifact
            }
            steps {
            // archive build on S3
                withAWS() {
                    s3Upload(
                            workingDir: 'build/libs/',
                            includePathPattern: '*-all.jar',
                            bucket: 'yellow-artifacts',
                            path: "webcam-worker-lambda/${artifactFolder}/"
                    )
                }

                // deploy build to lambda
                sh './gradlew deploy'
            }
        }

I've spent hours going over all the configurations of the different lambdas, comparing them, looking for differences that might be a source of the issue, but I'm pretty much out of ideas where the problem might be located by now.我花了几个小时检查不同 lambda 的所有配置,比较它们,寻找可能是问题根源的差异,但我现在几乎不知道问题可能在哪里。 Anybody got any hunches?有人有预感吗?

I figured it out.我想到了。 You better not hold anything in your mouth, because this is hilarious !你最好不要把任何东西含在嘴里,因为这太搞笑了!

Basically being all out of options, I locked on to the last discernible difference between this deployment and the ones that worked: The filesize of the jar being deployed.基本上没有选择,我锁定了此部署与有效部署之间的最后一个明显区别:正在部署的 jar 的文件大小。 The one that failed was by far the smallest.失败的是迄今为止最小的。 So I bloated it up by some 60% to make it comparable to everything else... and that fixed it!所以我把它膨胀了大约 60% 以使其与其他所有东西相媲美......并且修复了它!

This sounds preposterous.这听起来很荒谬。 Here's my hypothesis on what's going on: If the upload takes too little time, the lambda somehow needs longer to change its state.这是我对正在发生的事情的假设:如果上传时间太短,lambda 不知何故需要更长的时间来更改其 state。 I'm not sure why that would be, you'd expect the state to change when things are done , not to take longer if things are done faster, right?我不确定为什么会这样,您希望 state 在事情完成后会发生变化,如果事情完成得更快,则不会花费更长的时间,对吧? Maybe there's a minimum time for the state to remain?也许 state 的保留时间最短? I wouldn't know.我不会知道的。 There's one thing to support this hypothesis, though: The deployment from my local computer always worked.不过,有一件事可以支持这个假设:从我的本地计算机进行部署总是有效的。 That upload would naturally take longer than jenkins needs from inside the aws vpc.从 aws vpc 内部上传的时间自然会超过 jenkins 需要的时间。 So this hypothesis, as ludicrous as it sounds, fits all the facts that I have on hand.所以这个假设,尽管听起来很荒谬,但却符合我手头的所有事实。

Maybe somebody with a better understanding of the lambda-internal mechanisms can add a comment to this explaining how this can happen...也许对 lambda 内部机制有更好理解的人可以对此添加评论,解释这是如何发生的......

in my case it is solved after I added aws:states:opt-out in the description of my Lambda as explained in here: https://aws.amazon.com/de/blogs/compute/coming-soon-expansion-of-aws-lambda-states-to-all-functions/在我的情况下,我在 Lambda 的描述中添加aws:states:opt-out后解决了,如下所述: https://aws.amazon.com/de/blogs/compute/coming-soon-expansion-of -aws-lambda-states-to-all-functions/

ResourceConflictException means the resource already exists, or another operation is in progress ResourceConflictException表示资源已经存在,或者正在进行另一个操作

You cannot invoke a Lambda function or modify it again, if a previous configuration update has not yet completed.如果之前的配置更新尚未完成,您将无法调用 Lambda 函数或再次修改它。 If you do take an action like create or modify a function, and very shortly after that, while the function is still in Pending state due to the previous action, you may face this error.如果您确实采取了创建或修改函数之类的操作,并且在此之后不久,而该函数由于先前的操作仍处于 Pending 状态,您可能会遇到此错误。 Here is a short description about it. 是关于它的简短描述。

The LastUpdateStatus , LastUpdateStatusReason , and LastUpdateStatusReasonCode fields in the response from GetFunctionConfiguration indicate when the update is complete and the function is processing events with the new configuration.来自GetFunctionConfiguration的响应中的LastUpdateStatusLastUpdateStatusReasonLastUpdateStatusReasonCode字段指示更新何时完成以及函数正在使用新配置处理事件。 For more information, see Lambda function states .有关更多信息,请参阅Lambda 函数状态

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

相关问题 AWS CloudFront Lambda@Edge 部署 - AWS CloudFront Lambda@Edge deployment 部署后获取更新的 AWS Lambda URL - Get updated AWS Lambda URL after deployment 使用 Jenkins 嵌套部署 AWS Lambda 函数 - Nested deployment of AWS Lambda funtions with Jenkins 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 将简单的 node.js 应用程序部署到 AWS Lambda 无服务器失败并出现 GeneralServiceException - Deployment of simple node js application to AWS Lambda Serverless Failing with GeneralServiceException 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 在 AWS Lambda 中运行 .NET 6 Web API 项目,部署为 ZIP - Running .NET 6 Web API project in AWS Lambda with ZIP deployment 我想使用 kube.netes API 从 AWS Lambda function 重新启动部署 - I want to use kubernetes API to restart the deployment from the AWS Lambda function AWS python lambda 部署 package 我怎样才能从源代码管理中提取源代码或 package? - AWS python lambda deployment package how can i just pull the source or package from source control? AWS Lambda GitLab CI/CD 部署 package 大小比从我的本地环境部署大得多 - AWS Lambda GitLab CI/CD deployment package size is much bigger than deploy from my local environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM