简体   繁体   English

Cloudformation:您请求的资源不存在

[英]Cloudformation: The resource you requested does not exist

I have a cloudformation stack which has a Lambda function that is mapped as a trigger to an SQS queue.我有一个 cloudformation 堆栈,它有一个 Lambda function 作为触发器映射到 SQS 队列。

What happened was that I had to delete the mapping and create it again manually cos I wanted to change the batch size .发生的事情是我不得不删除映射并再次手动创建它,因为我想更改batch size Now when I want to update the mapping the cloudformation throws an error with The resource you requested does not exist.现在,当我想更新映射时,cloudformation 会抛出错误, The resource you requested does not exist. message.信息。

The resource mapping code looks like this:资源映射代码如下所示:

"EventSourceMapping":{
        "Properties":{
            "BatchSize":5,
            "Enabled":"true",
            "EventSourceArn":{
                "Fn::GetAtt":[
                    "ProcessorQueue",
                    "Arn"
                ]
            },
            "FunctionName":{
                "Fn::GetAtt":[
                    "ProcessorLambda",
                    "Arn"
                ]
            }
        },
        "Type":"AWS::Lambda::EventSourceMapping"
    }

I know that I've deleted the mapping cloudformation created initially and added it manually which is causing the issue.我知道我已经删除了最初创建的映射 cloudformation 并手动添加了它,这是导致问题的原因。 How do I fix this?我该如何解决? Cos I cannot push any update now.因为我现在无法推送任何更新。

Please help请帮忙

What you did, from my perspective, it is a mistake.你所做的,在我看来,是一个错误。 When you use Cloud Formation you are not suppose to apply changes manually.当您使用 Cloud Formation 时,您不应该手动应用更改。 You can, and maybe that's fine since one may don't care about the stack once is created.你可以,也许这很好,因为一旦创建堆栈,人们可能不关心堆栈。 But since you are trying to update the stack, this tells me that you want to keep the stack and update it on a time basis.但是由于您正在尝试更新堆栈,这告诉我您希望保留堆栈并定期更新它。

To narrow down your problem, first let make clear that the manually-created mapping is out of sync with your cloud formation stack.要缩小问题范围,首先要明确手动创建的映射与您的云形成堆栈不同步。 So, from a cloud formation perspective, it doesn't matter if you keep that mapping or not.因此,从云形成的角度来看,是否保留该映射并不重要。 I'm wondering, what would happen if you keep the manually-created mapping and create a new from Cloud Formation?我想知道,如果您保留手动创建的映射并从 Cloud Formation 创建一个新映射会发生什么? Maybe it will complain, since you would have repeated mappings for the same pair of (lambda,queue).也许它会抱怨,因为您会对同一对 (lambda,queue) 进行重复映射。 Try this:尝试这个:

  1. Create a change for your stack, where you completely remove the EventSourceMapping resource from your script.为您的堆栈创建一个更改,从脚本中完全删除EventSourceMapping资源。 This step is to basically clean loosing references.这一步基本上是清理丢失的引用。 Apply the change set.应用更改集。
  2. Then, and this is where I think you may get some kind of issue, add back again EventSourceMapping to your stack.然后,这就是我认为您可能会遇到某种问题的地方,再次将EventSourceMapping添加回您的堆栈。

If you get errors in the step 2, like "this mapping already exists", you will have to remove the manually-created mapping from the console.如果您在步骤 2 中遇到错误,例如“此映射已存在”,则必须从控制台中删除手动创建的映射。 And then try again step 2.然后重试第 2 步。

You probably know now that you should not have removed the resource manually.您现在可能知道您不应该手动删除资源。 If you change the CF, you can update it without changing resources which did not change in CF.如果更改了 CF,则可以在不更改 CF 中未更改的资源的情况下更新它。 You can try to replace the resource with the exact same physical name https://aws.amazon.com/premiumsupport/knowledge-center/failing-stack-updates-deleted/ The other option is to remove the resource from CF, update, and then add it back and update again - from the same doc.您可以尝试使用完全相同的物理名称替换资源https://aws.amazon.com/premiumsupport/knowledge-center/failing-stack-updates-deleted/另一种选择是从 CF 中删除资源,更新,然后将其添加回来并再次更新 - 来自同一个文档。

While comments above are valid, I found it interesting, that no one mentioned much simpler option: using SAM commands ( sam build / sam deploy ).虽然上面的评论是有效的,但我发现有趣的是,没有人提到更简单的选项:使用 SAM 命令( sam build / sam deploy )。 It's understandable that during the development process and designing the architecture, there might be flaws and situations where manual input in the console is necessary, therefore there's something I reference to every time I have similar issue.可以理解的是,在开发过程和设计架构过程中,可能会出现缺陷和需要在控制台手动输入的情况,因此每次遇到类似问题时都会参考一些内容。

  1. Simply comment out the chunk of code that is creating troubles, run sam build/deploy on top of it, CloudFormation stack will recognize that the resource no longer in the template and will delete it.简单地注释掉造成问题的代码块,在其上运行sam build/deploy ,CloudFormation 堆栈将识别出模板中不再存在的资源并将其删除。
  2. Now, since the resource is no longer in the architecture anyway(removed manually prior), it will have no issues passing the step and successfully updating the stack.现在,由于资源不再存在于体系结构中(之前已手动删除),因此通过该步骤并成功更新堆栈将没有问题。
  3. Then simply uncomment, make any necessary changes (if any) and deploy.然后简单地取消注释,进行任何必要的更改(如果有的话)并部署。

Works every time.每次都有效。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM