Skip to content

[FEATURE] localStack to startup resources on local mathine #10

@Blankll

Description

@Blankll

User Story

As a developer, I want to start up my local serverless resources to verify/test the functionaries before pushing them to a remote server.

Definition of Done:

  • enable support for FC localStack that able to accept user request
  • enable support for ApiGateway localStack able to accept user requests and forward them to fc and return the response to the user

Context & Background

serverless functions

sample of Aliyun invoke FC:

aliyun fc POST /2023-03-30/functions/{functionName}/invocations --region ap-southeast-1 --header "Content-Type=application/json" --body "{}"

It supports a flag --endpoint metrics.cn-qingdao.aliyuncs.com to specify the link and port

Aliyun web trigger url format:
public: http://<fc-name>-<random-id>.<region>.fcapp.run
private: https://<fc-name>-<random-id>.<region>-vpc.fcapp.run

sample of AWS invoke lambda:

aws lambda invoke \
    --function-name my-function \
    --cli-binary-format raw-in-base64-out \
    --payload '{ "name": "Bob" }' \
    response.json

AWS Lambda function URL format: https://abcd1234efgh.lambda-url.ap-northeast-1.on.aws/
It also supports the flag aws --endpoint-url=http://localhost:4566 kinesis list-streams to specify the link and port

localstack provides its own CLI and also supports invoke through config --endpoint-url

awslocal kinesis list-streams
# aws --endpoint-url=http://localhost:4566 kinesis list-streams

ApiGateway

aliyun Apigateway invoke url format: http://<random-id>-cn-hangzhou.alicloudapi.com"

AWS API Gateway generates a default invoke URL: https://abcdef123.execute-api.us-east-2.amazonaws.com
The localStack exposes two endpoints for the user to invoke:

http://<REST_API_ID>.execute-api.localhost.localstack.cloud:4566/dev/test
http://localhost:4566/_aws/execute-api/<REST_API_ID>/dev/test

Buckets

AWS generates bucket URL: https://my-bucket-123.s3.ap-northeast-1.amazonaws.com
for a website bucket, the default website URL: http://my-website-bucket.s3-website-ap-northeast-1.amazonaws.com

Aliyun generates bucket URL: https://mybucket.cn-hangzhou.aliyuncs.com
for a website bucket, the default website URL: http://mywebsite.cn-hangzhou.aliyuncs.com
Hence, for Aliyun, the general bucket and website bucket use the same URL.

Solutions

serverlessinsight allows spinning up several stacks:

  • single/ multi lambda only
  • single/multi buckets only
  • lambdas with integrated event sources (eg, API gateway)
  • datasources only
  • full stack with lambda, event sources, datasources, and buckets

To achieve the capability of accessing a single service, like invoking a function in a stack, it requires spinning up a server gateway that routes requests to corresponding resources.

  • spinning up front-door server: localhost:4567
  • Each defined resources spin up its own instance, and it is callable through localhost:4567
  • integrations between those resources also through the localhost:4567

as the solutions above, the resource endpoints will look like:

resource Endpoint
function http://localhost:4567/si_functions/<function_id>-<function_name>-<region>/<other_paths>
bucket http://localhost:4567/si_buckets/<bucket_id>-<bucket_name>-<region>/<other_paths> (api endpoint)
http://localhost:4567/si_website_buckets/<bucket_id>-<bucket_name>-<region>/<other_paths> (to visit website)
Events `http://localhost:4567/si_events/<gateway

Tasks

  • localStack front-door setup
  • implement localStack functions
  • implement localStack events - api-gateway
  • implement localStack bucket

Reference

localStack: https://www.localstack.cloud/.
aws-local: https://github.com/localstack/awscli-local.
serverless-offline: https://www.serverless.com/plugins/serverless-offline#httpport

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions