Here is what I came up with so far
Project folder structure:
project folder1 main.go folder2 main.go buildspec.yml template.yml
buildspec.yml:
... build: commands: - cd folder1 - go build -o main - cd ../folder2 - go build -o main ....
template.yml:
.... Resources: GetTest1: Type: AWS::Serverless::Function Properties: CodeUri: ./folder1 Handler: main Runtime: go1.x Role: Fn::ImportValue: !Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']] Events: GetEvent: Type: Api Properties: Path: /test1 Method: get GetTest2: Type: AWS::Serverless::Function Properties: CodeUri: ./folder2 Handler: main Runtime: go1.x Role: Fn::ImportValue: !Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']] Events: GetEvent: Type: Api Properties: Path: /test2 Method: get ....
It is important to note that all the main.go files in the subdirectories, namely folder1/main.go , folder2/main.go , must be in the package main , otherwise this will not work.
source share