2
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.

serverless framework でローカルPCの環境変数を参照するやり方

Posted at

公式の説明に書いてある様にローカルPCの環境変数を使うには${env:SOME_VAR}を使うらしいです。

自分の場合、cloudfrontに事前に取得したACMのARNを設定するために環境変数を使用したい。

  CloudFrontDistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Aliases:
          - ${self:custom.siteName}
        Origins:
          - DomainName: ${self:custom.siteName}.s3-website-${self:provider.region}.amazonaws.com
            Id: S3Origin
            CustomOriginConfig:
              HTTPPort: 80
              HTTPSPort: 443
              OriginProtocolPolicy: http-only
        Enabled: true
        DefaultRootObject: index.html
        DefaultCacheBehavior:
          AllowedMethods:
            - GET
            - HEAD
          TargetOriginId: S3Origin
          ForwardedValues:
            QueryString: true
            Cookies:
              Forward: none
          ViewerProtocolPolicy: redirect-to-https
        ViewerCertificate:
          AcmCertificateArn: ${env:ACM_ARN} # こんな感じで使いたい
          SslSupportMethod: sni-only

どうやって設定するのか

macOSの場合

#設定方法
$ export ACM_ARN=arn:aws:acm:us-east-1:xxxxxxxxxx:certificate/xxxxxxxxxxxxxxx

#確認
$ echo $ACM_ARN
=> arn:aws:acm:us-east-1:xxxxxxxxxx:certificate/xxxxxxxxxxxxxxx

#全ての環境変数を確認する
$ set

#削除
$ unset ACM_ARN

$ echo $ACM_ARN
=> 何も表示されない

以上で設定ができます

2
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
2
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?