내용으로 건너뛰기

Adding configuration file to lambda using SAM rust-cargolambda BuildMethod

0

I have small configuration file(local.yaml) and want to include it to lambda built by cargo lambda.

When using cargo lambda only, I can include config.yaml by running cargo lambda build --output-format zip --include config.yaml.

However, when using sam template.yaml I can't find which section of template I need to modify in order to include config.yaml.

Here's the sam template file that builds the lambda function without the file included.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Globals:
  Function:
    MemorySize: 128
    Architectures: [ "arm64" ]
    Handler: bootstrap
    Runtime: provided.al2
    Timeout: 5
    Tracing: Active
    Environment:
      Variables:
        RUST_LOG: info

Resources:
  LoginGuestLoginFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: lambda/login/
      Events:
        Api:
          Type: HttpApi
          Properties:
            Path: /guest_login
            Method: GET
    Metadata:
      BuildMethod: rust-cargolambda
      Binary: guest_login

Outputs:
  ApiUrl:
    Description: "API Gateway endpoint URL"
    Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/"

질문됨 2년 전520회 조회

1개 답변
0

Including config.yaml in Your AWS SAM Lambda Deployment If you're using AWS SAM with rust-cargolambda to build your Lambda function, and you want to include a config.yaml file, here's how you can do it:

  1. Update Your SAM Template In your template.yaml, you need to tell SAM to include the config.yaml file during the build process. Here's how you can modify it:

yaml

Resources:
  LoginGuestLoginFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: lambda/login/
      # Your function code lives here
    Metadata:
      BuildMethod: rust-cargolambda
      Binary: guest_login
      BuildProperties:
        ExtraFiles:
          - config.yaml  # This tells SAM to include config.yaml
  1. Place config.yaml in the Right Directory Make sure your config.yaml file is in the lambda/login/ directory, or update the path in the ExtraFiles section if it's located somewhere else.

  2. Build and Deploy After updating the template, you can build and deploy your Lambda function with these commands:

bash

sam build
sam deploy --guided

This will include the config.yaml file in your Lambda deployment package.

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠