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/"
ik1ne
asked a month ago233 views
1 Answer
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.

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions