简体   繁体   中英

Deploying lambda function using serverless framework

I've successfully deployed my lambda function (in Nodejs runtime) using the serverless framework
The thing is that serverless deploy also creates a bunch of AWS services which I do not want such as:

  • API gateway - I Don't since I have my own API gateway already
  • S3 bucket - I Don't need to see any output logs
  • Cloudwatch - I Don't need to see any logs since we have our logs infrastructure

Q: Is there anyway to tell serverless to deploy just the lambda function? (Or at least avoid the API gateway)

The Serverless Framework creates an S3 bucket as a way to get your service into AWS. Instead of trying to push directly at the Lambda service, it packages it in a zip, uploads to S3 and then points at that S3 bucket for the deployment process to know where to find stuff. You can specify your own S3 bucket which should be used to store all the deployment artifacts. The deploymentBucket config which is nested under provider lets you eg set the name or the serverSideEncryption method for this bucket. If you don't provide your own bucket, Serverless will create a bucket which uses default AES256 encryption.

As for the API Gateway, if you want to use an existing API Gateway resource (no real need to though as they cost nothing unless there is traffic going through them), you can share the same API Gateway between multiple projects by referencing its REST API ID and Root Resource ID in serverless.yml as follows:

service: service-name
provider:
  name: aws
  apiGateway:
    restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework
    restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path
    websocketApiId: xxxxxxxxxx # Websocket API resource ID. Default is generated by the framework
    description: Some Description # optional - description of deployment history

functions: ...

You should reconsider using CloudWatch at least at a basic level. It is the only way you can get output from your functions unless you tie in a service that makes API requests which can add latency to your service. CloudWatch doesn't add latency (or at least so small as to be insignificant). However, if you really must turn CloudWatch off, you can't stop it creating the log group in ClouWatch but you can restrict the time for logs to live to 0 or a small number of days:

provider:
  logRetentionInDays: 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM