2017-12-22 8 views
0

Serverlessフレームワークを使用する私のサービスで、さまざまな環境で異なるリソースを使用したいと考えています。ステージに応じてサーバーレスフレームワークで異なるリソースを処理する方法

は私が含まれていdev-resources.ymlという名前のファイルにすべてのリソースを置く:

Resources: 

    SQSQueue: 
     Type: AWS::SQS::Queue 
     Properties: 
     QueueName: ${self:service}-${self:provider.stage}-queue 

    SNSTopic: 
     Type: AWS::SNS::Topic 
     Properties: 
     DisplayName: APU SNS Topic 
     TopicName: ${self:service}-${self:provider.stage}-topic 

    SNSSubscription: 
     Type: AWS::SNS::Subscription 
     Properties: 
      Endpoint: [email protected] 
      Protocol: email 
      TopicArn: { "Fn::Join" : ["", ["arn:aws:sns:${self:provider.region}:", { "Ref" : "AWS::AccountId" }, ":${self:resources.Resources.SNSTopic.Properties.TopicName}" ] ] } 

をそして私はこのようにそれをインポートしようとしている:

resources: ${file(./${self:provider.stage}-resources.yml)} 

をしかし、私はserverless deployを実行しようとすると、それは何もせずに立ち往生した。ここで

あなたは上のデバッグで何が起こるかフィンすることができます

Serverless: Load command run 
Serverless: Load command config 
Serverless: Load command config:credentials 
Serverless: Load command create 
Serverless: Load command install 
Serverless: Load command package 
Serverless: Load command deploy 
Serverless: Load command deploy:function 
Serverless: Load command deploy:list 
Serverless: Load command deploy:list:functions 
Serverless: Load command invoke 
Serverless: Load command invoke:local 
Serverless: Load command info 
Serverless: Load command logs 
Serverless: Load command login 
Serverless: Load command logout 
Serverless: Load command metrics 
Serverless: Load command print 
Serverless: Load command remove 
Serverless: Load command rollback 
Serverless: Load command rollback:function 
Serverless: Load command slstats 
Serverless: Load command plugin 
Serverless: Load command plugin 
Serverless: Load command plugin:install 
Serverless: Load command plugin 
Serverless: Load command plugin:uninstall 
Serverless: Load command plugin 
Serverless: Load command plugin:list 
Serverless: Load command plugin 
Serverless: Load command plugin:search 
Serverless: Load command emit 
Serverless: Load command config 
Serverless: Load command config:credentials 
Serverless: Load command rollback 
Serverless: Load command rollback:function 

何が起こっている上の任意の提案?または、さまざまな段階で異なるリソースを使用する方法は?

+0

'serverless.yml'ファイル全体を投稿すると役に立ちます。 – dashmug

答えて

0

私はサーバーレスの初心者です。私はあなたの設定がうまくいかない理由を本当に知りません、もしあなたが明示的に展開をserverless deploy --stage prodと呼んでいるのであれば、それは動作しますか?個人的に

ごとの段階の環境を使用するため、私はthis setupを以下のよ:

serverless.ymlで:

その後
provider: 
    ... 
    environment: 
    MY_VAR: "${self:custom.secrets.MY_VAR}" 
... 
custom: 
    stage: ${opt:stage, self:provider.stage} 
    secrets: ${file(secrets.yml):${self:custom.stage}} 

secrets.ymlに:

default: &default 
    <<: *default 
    MY_VAR: "foo bar" 

dev: 
    <<: *default 

stage: 
    <<: *default 

prod: 
    <<: *default 
    MY_VAR: "something else for prod" 

その後serverless deploy --stage prodとそれがどの変数を操縦します引き込まれます..

関連する問題