Fork me on GitHub
#holy-lambda
<
2021-10-25
>
Benjamin09:10:41

what is a good way to implement multiple endpoints? When I call the lambda with the url like https//aws.my-thing/foo does the foo appear somewhere? I can also make it depend on the headers or content or sth

Karol Wójcik09:10:49

There are two approaches. 1. One lambda per one endpoint 2. One lambda for multiple endpoints. At Retailic we're using the second approach, where we have an integration between regular ring/muuntaja stack and holy-lambda. But if you don't want to use ring, then just print the event. All the necessary properties are there. To use HL with multiple endpoints specify a proxy+ in template.yml like so:

RetailicFabloApiLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Policies:
        - Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
              - "ec2:CreateNetworkInterface"
              - "ec2:DeleteNetworkInterface"
              - "ec2:DescribeNetworkInterfaces"
              - "ec2:DetachNetworkInterface"
            Resource: "*"
        - Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
              - "rds-db:connect"
            Resource:
              - !Ref RDSConnectionIAMARN
      VpcConfig:
        SecurityGroupIds: !Ref SecurityGroupIds
        SubnetIds: !Ref PrivateSubnetIds
      Environment:
        Variables:
          DATABASE_URL: !Ref DatabaseConnectionURL
          PUBLIC_URL: !Sub "https://${DomainName}"
          FRONTEND_URL: !Ref FrontendURL
      FunctionName: !Sub "RetailicFabloApiLambdaFunction-${Environment}"
      PackageType: Image
      ImageUri: !Ref ImageUri
      Events:
        HttpProxyEvent:
          Type: HttpApi
          Properties:
            ApiId: !Ref RetailicHttpApi
            Path: /{proxy+}
            Method: ANY

Karol Wójcik09:10:06

You need just proxy+ 🙂

Benjamin09:10:03

cool will check. Btw what is a good way to test without using aws sam? Like the -main function get's called I guess with some payload

Karol Wójcik10:10:08

You mean unit tests or just making sure it will work on AWS as well?

Karol Wójcik10:10:52

or like you're looking for something like regular ring server that you can span, kill, restart at any time etc?

Benjamin11:10:44

Don't mean unit tests, but simulating the way aws is calling the program + having it running in the repl @U0510KXTU example seems to do that; Will check it out. For my usecase I just need 1 example input data kinda then build the flesh of my program.