Help us understand the problem. What is going on with this article?

Serverless Framework v1 で --profileオプション / --regionオプションを作って AWS CLI credentialsを活用する

More than 3 years have passed since last update.

バージョン

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G1004
$
$ $(npm bin)/sls -v
1.0.0-rc.2
$

何がしたかったか

serverless.yml に profile を直接書きたくなかった。

https://serverless.com/framework/docs/providers/aws/setup/#using-aws-profiles

service: new-service
provider:
  name: aws
  runtime: nodejs4.3
  stage: ${opt:stage, self:custom.defaultStage}
  profile: ${self:custom.profiles.${self:provider.stage}}
custom:
  defaultStage: dev
  profiles:
    #ここ
    dev: devProfile
    #ここ
    prod: prodProfile

みたいにprofile名を直接書いちゃうとgit repoにのせずらいなーと思った。

なおかつ、slsコマンドが AWS_DEFAULT_PROFILE 環境変数を見ない感じだった。

こうした

service: test-sls-v1
provider:
  name: aws
  runtime: python2.7
  stage: ${opt:stage, self:custom.defaultStage}
  #profileオプション追加
  profile: ${opt:profile, self:custom.defaultProfile}
  #regionオプション追加
  region: ${opt:region, self:custom.defaultRegion}
custom:
  defaultStage: dev
  #何も指定がなければ default profile
  defaultProfile: default
  #何も指定がなければ 東京リージョン
  defaultRegion: ap-northeast-1
functions:
  hello:
    handler: handler.hello

こんな感じでprofileオプションを指定できるので AWS CLIぽく使える。

$ $(npm bin)/sls deploy --profile hogehoge-user

参考:

serverless/credentials.md at master · serverless/serverless

https://github.com/serverless/serverless/blob/master/docs/providers/aws/guide/credentials.md

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした