1
votes

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)

1
If you are not creating any http endpoint it will not create the api gateway. probably there's a way to disable s3 and cloudwatch for logs - Elias Soares
if you really just want the lambda function, you can do serverless deploy function - Elias Soares
For S3, are you talking about the S3 bucket that sls creates to host the packaged assets (including the Lambda function)? If so, see Artifacts hosted on S3. - jarmod

1 Answers

1
votes

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 e.g. 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