AWSの環境(契約)2つ(会社・個人)をdevとstgで使い分けています。
アクセスキー、シークレットアクセスキーもそれぞれ取得しています。
defaultをDevとしてプロファイルの設定は以下のようになっております。
>$ aws configure --profile stg AWS Access Key ID [****************AAAA]: AWS Secret Access Key [****************SSss]: Default region name [None]: Default output format [None]: >$ aws configure AWS Access Key ID [****************BBBB]: AWS Secret Access Key [****************ttTT]: Default region name [None]: Default output format [None]:
この状態で
>$ sls deploy --stage stg >$ sls deploy >$ sls deploy --profile stg --stage stg -v
を叩くと、全てdev側にdeployされてしまいます。
どのようにすればプロファイルstgの方にdeployすることができるでしょうか?
serverless.ymlの設定は以下になります。
service: test-service provider: name: aws runtime: nodejs8.10 region: ap-northeast-1 stage: ${opt:stage, self:custom.defaultStage} custom: defaultStage: dev profiles: stg: stg otherfile: environment: dev: ${file(./lambda_conf/dev.yml)} stg: ${file(./lambda_conf/stg.yml)} package: include: - utils/** functions: pointsearch: handler: handler.get environment: Other_File: ${self:custom.otherfile.environment.${self:provider.stage}.stage} events: - http: path: testpath method: get
参照の確認
$ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************BBBB shared-credentials-file secret_key ****************ttTT shared-credentials-file region ap-northeast-1 config-file ~/.aws/config $ aws configure list --profile stg Name Value Type Location ---- ----- ---- -------- profile stg manual --profile access_key ****************AAAA shared-credentials-file secret_key ****************SSss shared-credentials-file region ap-northeast-1 config-file ~/.aws/config mbp:banner_point_api epark$
追記1
configureのdefaultに書かれている[アクセスキー][シークレットキー]をstgに書いていた[アクセスキー][シークレットキー]に書き換えてdeploy -vを行ったところ、以下のerrorMessageが表示されました。
User: arn:aws:iam::999999999999:user/Kuniatsu is not authorized to perform:
権限がないと言っているので、deployコマンドを実行時にdeploy先の指定はconfigureのアクセスキーで指定できるわけではなく、どこか別の場所にdeploy先の指定があると考えられそうです。向きさきがdevなのにアクセスキーなどがstg用のものなのでerrorが出たと考えられると思います。
思い当たる設定場所がありませんが、向き先の指定をしている場所を探してみます。
追記2
serverless.ymlに
provider: profile: ${opt:stage, self:custom.defaultStage}
を追記、--stage stgにすると[追記1]のエラーが発生する。
この追記で、profileがstgを読むようになった。だが、向きさきは以前devのまま。
向きさきを変える方法を探す。
追記3
http://takayukinakata.hatenablog.com/entry/2018/03/30/193413
こちらのサイトでは
serverless deploy --aws-profile production
という書き方がされている、よって
serverless deploy --aws-profile stg
で試してみた。がダメ、
ひょっとするとシークレットキーが間違っているのではないかと疑う。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。