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

Lambda レイヤー カスタム makefile を使用してレイヤーを構築する

Posted at

Lambda レイヤー カスタム makefile を使用してレイヤーを構築する

Lambda レイヤー カスタム makefile を使用してレイヤーを構築する

ディレクトリ構成

├── layer
│   └── node-base-layer
│       └── Makefile # 大文字「M」
├── package.json
└── template.yaml

SAM template

./template.yaml
Globals:
  Function:
    Layers:
      - !Ref NodeBaseLayer  # 使用するレイヤー

Resources:
  # -------------------------
  # Lambda レイヤーの構築
  # -------------------------
  NodeBaseLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      LayerName: node-base-layer  # レイヤーの名前
      ContentUri: layer/node-base-layer  # レイヤーのコンテンツURI
      CompatibleRuntimes:
        - !Ref FunctionRuntime  # 対応するランタイム
      RetentionPolicy: Delete  # レイヤーの保持ポリシー
    Metadata:
      BuildMethod: makefile

  NodeBaseLayerPermission:
    Type: AWS::Lambda::LayerVersionPermission
    Properties:
      Action: lambda:GetLayerVersion  # アクション: レイヤーのバージョン取得
      LayerVersionArn: !Ref NodeBaseLayer  # 対象のレイヤーARN
      Principal: !Ref AWS::AccountId  # アクセスを許可するプリンシパル

Makefile

  • ファイル名は、大文字から始める
  • cdは使えない
  • リソースには、ARTIFACTS_DIRからの相対パスで!
./layer/node-base-layer/Makefile

# build-(LogicalResourceId)
build-NodeBaseLayer:
	mkdir -p "$(ARTIFACTS_DIR)/nodejs"

	# package.jsonをコピー
	cp "$(ARTIFACTS_DIR)/../../../package.json" "$(ARTIFACTS_DIR)/nodejs" 

	# モジュールのインストール
	npm install --omit=dev --prefix "$(ARTIFACTS_DIR)/nodejs"
0
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
0
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?