导入已有资源到新的CloudFormation堆栈中

0

【以下的问题经过翻译处理】 我有一个现有的S3存储桶,我想将其导入到一个新的CloudFormation堆栈中。ExistingDestinationBucket已经存在。

我找到的AWS文档详细说明了从现有资源创建一个全新的堆栈,或者将现有资源添加到现有堆栈中,但这两种方法都不能满足我的需求。我需要将S3存储桶包含在堆栈中,以便我可以为Lambda函数定义触发器。以下是我的CloudFormation模板。

在以导入形式运行时,AWS要求我标识现有的Lambda函数 - 但这个函数不存在。当作为全新资源运行时,我收到一个错误,指出该存储桶已经存在。

是否有办法实现我所需的操作?

AWSTemplateFormatVersion: "2010-09-09"
Description: "Lighthouse run infrastructure"
Resources:

    ExistingDestinationBucket:
        Type: "AWS::S3::Bucket"
        DeletionPolicy: "Retain"
        Properties:
            BucketName: !Sub "rapidspike-pages-lambda-${AWS::Region}"
            NotificationConfiguration:
                LambdaConfigurations:
                    Event: "s3:ObjectCreated:*"
                    Filter: "*/summary.json"
                    Function: !Ref PostProcessingFunc

    PostProcessingFunc:
        Type: "AWS::Lambda::Function"
        Properties:
            Description: ""
            FunctionName: "lighthouse-run-post-processing"
            Handler: "src/handlers/handler.handler"
            Code:
                S3Bucket: !Sub "lighthouse-run-functions-ap-south-1"
                S3Key: "postprocess.zip"
            MemorySize: 512
            Runtime: "nodejs16.x"
            Timeout: 60
            TracingConfig:
                Mode: "PassThrough"
            EphemeralStorage:
                Size: 512
1 Antwort
0

【以下的回答经过翻译处理】 是的,有一种方法可以实现你想要的操作,但需要分为多个步骤。

步骤1:更新你上面显示的模板,只保留S3存储桶,不包含堆栈中的其他资源。使用导入选项使用此模板创建一个新的堆栈。

步骤1的结果将是一个堆栈,其中只有一个资源,即现有S3存储桶的导入资源。

步骤2:将在步骤1中删除的资源重新放入模板中,然后对现有堆栈执行堆栈更新(不是导入)。

这将向堆栈添加新资源(Lambda函数),在更新完成后,你应该得到最初想要的情况。

profile picture
EXPERTE
beantwortet vor 6 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen