Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I excluded folder from sam deploy command?

I run this to deploy my lambda:

sam package --template-file prod_template.yaml --s3-bucket mybucket --output-template-file packaged-template.yaml
sam deploy --template-file packaged-template.yaml --stack-name mystack --capabilities CAPABILITY_IAM

That works but this code is version controlled and sam is also uploading the .git folder. How do I have sam ignore some folders like I can with gitignore?

like image 821
red888 Avatar asked Jan 22 '18 21:01

red888


People also ask

How do I remove Sam deployment?

Deletes an AWS SAM application by deleting the AWS CloudFormation stack, the artifacts that were packaged and deployed to Amazon S3 and Amazon ECR, and the AWS SAM template file.

How do I deploy using SAM CLI?

To have the AWS SAM CLI create these repositories, use either the --resolve-image-repos option or the --guided option, and then respond to the subsequent prompt with Y . Specify this option to have the AWS SAM CLI use prompts to guide you through the deployment.

What two commands are required to redeploy lambda function using Sam?

The sam package and sam deploy commands are used to update and trigger the deployment of your Lambda function. You executed these commands in Package the AWS SAM application and Deploy the AWS SAM application.

What does Sam Package command do?

Packages an AWS SAM application. This command creates a . zip file of your code and dependencies, and uploads the file to Amazon Simple Storage Service (Amazon S3).


1 Answers

You need to check you're supplying a valid CodeUri path in your template, it should look something like this:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  Followers:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./src
      Handler: lambda.handler
      Runtime: nodejs12.x
      Timeout: 300

The AWS docs state that if the CodeUri is not supplied, the entire working directory will be zipped and uploaded (which I think is what you're experiencing).

If you specify a file [in CodeUri], the command directly uploads it to the S3 bucket. If you specify a folder, the command zips the folder and then uploads the .zip file. For most resources, if you don't specify a path, the command zips and uploads the current working directory.

like image 120
Lloyd Avatar answered Oct 01 '22 22:10

Lloyd