1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

sls deployするとStack with id lambda-demo-dev does not existエラー

Posted at

serverless frameworkでdeployエラー

lambdaとAPIGatewayの構成のスタックを今まで何回かdeployしてうまく行っていたのですが、
sls remove -vしたあとにsls deploy -vし直したときに以下のエラーが発生しました。

ServerlessError: Stack with id lambda-demo-dev does not exist

翻訳すると、**lambda-demo-dev のスタックが存在しません。**という内容。
調べていくとserverless.ymlの以下の記述が原因でした。

serverless.yml
service: lambda-demo

---------省略---------

resources:
  Outputs:
    ServiceEndpointTestRequest:
      Value: !Join
              - ''
              - - "curl -v -X GET -sS '"
                - ${cf:lambda-demo-dev.ServiceEndpoint}
                - "?person_id=001' -H 'Content-Type:application/json'|jq"


serverlessframeworkが自動で作成するOutputsであるServiceEndpointを使用したかったので、
自分自身のスタックのcfnの変数を参照していました。
sls deploy -vだけしている分には問題なかったのですが、sls remove -vすることで今まで参照していたcfnが削除され、sls deploy -vしてもスタックが存在しませんというエラーが出たようです。

解決方法

以下のように、ServiceEndpointを自分でcustomに作り直し、Outputsに組み込みました。

serverless.yml
service: lambda-demo

---------省略---------

custom:
  ServiceEndpoint: !Join
                    - ''
                    - - "https://"
                      - !Ref ApiGatewayRestApi
                      - ".execute-api."
                      - !Ref AWS::Region
                      - "."
                      - !Ref AWS::URLSuffix
                      - "/"
                      - ${self:provider.stage}

resources:
  Outputs:
    ServiceEndpointTestRequest:
      Value: !Join
              - ''
              - - "curl -v -X GET -sS '"
                - ${self:custom.ServiceEndpoint}
                - "?person_id=001' -H 'Content-Type:application/json'|jq"


参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?