Coder Social home page Coder Social logo

aws / aws-sam-cli Goto Github PK

View Code? Open in Web Editor NEW
6.4K 149.0 1.2K 77.93 MB

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM

Home Page: https://aws.amazon.com/serverless/sam/

License: Apache License 2.0

Go 0.03% JavaScript 0.02% Python 99.49% Makefile 0.04% C# 0.04% Java 0.07% Shell 0.20% Ruby 0.05% PowerShell 0.05%
serverless aws lambda serverlessapplicationmodel sam docker api-gateway python

aws-sam-cli's Introduction

AWS SAM CLI

Apache 2.0 License SAM CLI Version Install pip

Installation | Blogs | Videos | AWS Docs | Roadmap | Try It Out | Slack Us

The AWS Serverless Application Model (SAM) CLI is an open-source CLI tool that helps you develop serverless applications containing Lambda functions, Step Functions, API Gateway, EventBridge, SQS, SNS and more. Some of the features it provides are:

  • Initialize serverless applications in minutes with AWS-provided infrastructure templates with sam init
  • Compile, build, and package Lambda functions with provided runtimes and with custom Makefile workflows, for zip and image types of Lambda functions with sam build
  • Locally test a Lambda function and API Gateway easily in a Docker container with sam local commands on SAM and CDK applications
  • Sync and test your changes in the cloud with sam sync in your developer environments
  • Deploy your SAM and CloudFormation templates using sam deploy
  • Quickly create pipelines with prebuilt templates with popular CI/CD systems using sam pipeline init
  • Tail CloudWatch logs and X-Ray traces with sam logs and sam traces

Recent blogposts and workshops

  • Speeding up incremental changes with AWS SAM Accelerate and Nested Stacks - Read blogpost here.

  • Develop Node projects with SAM CLI using esbuild - and use SAM Accelerate on Typescript projects. Read blogpost here.

  • Speed up development with SAM Accelerate - quickly test your changes in the cloud. Read docs here.

  • AWS Serverless Developer Experience Workshop: A day in a life of a developer - This advanced workshop provides you with an immersive experience as a serverless developer, with hands-on experience building a serverless solution using AWS SAM and SAM CLI.

  • The Complete SAM Workshop - This workshop is a great way to experience the power of SAM and SAM CLI.

  • Getting started with CI/CD? SAM pipelines can help you get started - This workshop walks you through the basics.

  • Get started with Serverless Application development using SAM CLI - This workshop walks you through the basics.

Get Started

To get started with building SAM-based applications, use the SAM CLI. SAM CLI provides a Lambda-like execution environment that lets you locally build, test, debug, and deploy AWS serverless applications.

Next Steps: Learn to build a more complex serverless application.

What is this Github repository? ๐Ÿ’ป

This Github repository contains source code for SAM CLI. Here is the development team talking about this code:

SAM CLI code is written in Python. Source code is well documented, very modular, with 95% unit test coverage. It uses this awesome Python library called Click to manage the command line interaction and uses Docker to run Lambda functions locally. We think you'll like the code base. Clone it and run make pr or ./Make -pr on Windows!

Related Repositories and Resources

Contribute to SAM

We love our contributors โค๏ธ We have over 100 contributors who have built various parts of the product. Read this testimonial from @ndobryanskyy to learn more about what it was like contributing to SAM.

Depending on your interest and skill, you can help build the different parts of the SAM project;

Enhance the SAM Specification

Make pull requests, report bugs, and share ideas to improve the full SAM template specification. Source code is located on Github at aws/serverless-application-model. Read the SAM Specification Contributing Guide to get started.

Strengthen SAM CLI

Add new commands, enhance existing ones, report bugs, or request new features for the SAM CLI. Source code is located on Github at aws/aws-sam-cli. Read the SAM CLI Contributing Guide to get started.

Update SAM Developer Guide

SAM Developer Guide provides a comprehensive getting started guide and reference documentation. Source code is located on Github at awsdocs/aws-sam-developer-guide. Read the SAM Documentation Contribution Guide to get started.

Join the SAM Community on Slack

Join the SAM developers channel (#samdev) on Slack to collaborate with fellow community members and the AWS SAM team.

aws-sam-cli's People

Contributors

aahung avatar awood45 avatar aws-sam-cli-bot avatar c2tarun avatar coshus avatar dependabot[bot] avatar github-actions[bot] avatar hawflau avatar hnnasit avatar jfuss avatar joaoasrosa avatar jonife avatar lucashuy avatar mgrandis avatar mildaniel avatar mingkun2020 avatar mndeveci avatar moelasmar avatar paulmaddox avatar qingchm avatar resios avatar sanathkr avatar sapessi avatar sidhujus avatar sriram-mv avatar torresxb1 avatar valerena avatar viksrivat avatar wchengru avatar xazhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-sam-cli's Issues

Validation fails on uneven indentation

Running on this template - https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/inline_swagger/template.yaml, sam validate command panics at line-numbers.go

2017/08/11 12:08:53 0.1.0
2017/08/11 12:08:53 PANIC: YAML contains malformed structures
panic: PANIC: YAML contains malformed structures

goroutine 1 [running]:
log.Panicf(0x168d237, 0x29, 0x0, 0x0, 0x0)
	/home/ubuntu/bin/go/src/log/log.go:329 +0xda
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.ProcessLineNumbers(0xc420597000, 0x48b, 0xe00, 0x168c1c0, 0x27)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/line-numbers.go:116 +0xe8f
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.unmarshal(0xc420597000, 0x48b, 0xe00, 0x1680cef, 0x16, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/unmarshal.go:45 +0x403
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Parse(0xc420597000, 0x48b, 0xe00, 0x48b, 0xe00, 0x0, 0x0, 0xc4204c8028, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:49 +0xfe
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.read(0x1966360, 0xc4204c8028, 0xc4204c8028, 0x0, 0x0, 0x0, 0x1, 0x1)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:40 +0x105
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Open(0xc42007e467, 0xd, 0xc42007e467, 0xd, 0x13, 0x0, 0x0, 0xc420220f90)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:29 +0x27e
main.validate(0xc4203ce780)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/validate.go:13 +0x7a
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.HandleAction(0x1587e60, 0x169a720, 0xc4203ce780, 0xc4204b8a00, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:487 +0x7c
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.Command.Run(0x1677894, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x16971ee, 0xa7, 0x0, ...)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/command.go:207 +0xb72
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.(*App).Run(0xc420154680, 0xc42000a1e0, 0x2, 0x2, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:250 +0x7d0
main.main()
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/main.go:302 +0x1be1

aws cloudformation package should preserve comments and order

Given the template.yaml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  # This is a comment
  VotesTable:
    Type: AWS::Serverless::SimpleTable
  VoteSpacesTabs:
    # this is another comment
    Type: AWS::Serverless::Function
    Properties:
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Runtime: python3.6
      Environment:
        Variables:
          TABLE_NAME:
            Ref: VotesTable
      Events:
        Vote:
          Properties:
            Method: post
            Path: /
          Type: Api
      Timeout: 10

And the command:
aws cloudformation package --template-file pwd/template.yaml --s3-bucket ranman-code --output-template-file package.yaml

package.yaml should have:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  # This is a comment
  VotesTable:
    Type: AWS::Serverless::SimpleTable
  VoteSpacesTabs:
    # this is another comment
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: s3://ranman-code/97402a11ac040008e15358ccc872f799
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Runtime: python3.6
      Environment:
        Variables:
          TABLE_NAME:
            Ref: VotesTable
      Events:
        Vote:
          Properties:
            Method: post
            Path: /
          Type: Api
      Timeout: 10

Instead it has:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  VoteSpacesTabs:
    Properties:
      CodeUri: s3://ranman-code/97402a11ac040008e15358ccc872f799
      Environment:
        Variables:
          TABLE_NAME:
            Ref: VotesTable
      Events:
        Vote:
          Properties:
            Method: post
            Path: /
          Type: Api
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Runtime: python3.6
      Timeout: 10
    Type: AWS::Serverless::Function
  VotesTable:
    Type: AWS::Serverless::SimpleTable
Transform: AWS::Serverless-2016-10-31

sudo npm install fails

Most likely a bug with go-npm (https://github.com/sanathkr/go-npm) because it handles the installation. But filing a Issue here nevertheless for other folks to be aware of. A fix is on the way.

sudo npm install -g aws-sam-local
Password:
-
> [email protected] postinstall /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local
> go-npm install

Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.1.1/sam_0.1.1_darwin_amd64.tar.gz
fs.js:681
  return binding.rename(pathModule._makeLong(oldPath),
                 ^

Error: EACCES: permission denied, rename 'bin/sam' -> '/Users/sanathkr/.nvm/versions/node/v4.3.0/bin/sam'
    at Error (native)
    at Object.fs.renameSync (fs.js:681:18)
    at /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:62:12
    at /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:51:9
    at ChildProcess.exithandler (child_process.js:204:7)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
npm ERR! Darwin 16.6.0
npm ERR! argv "/Users/sanathkr/.nvm/versions/node/v4.3.0/bin/node" "/Users/sanathkr/.nvm/versions/node/v4.3.0/bin/npm" "install" "-g" "aws-sam-local"
npm ERR! node v4.3.0
npm ERR! npm  v2.14.12
npm ERR! code ELIFECYCLE

npm ERR! [email protected] postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script 'go-npm install'.
npm ERR! This is most likely a problem with the aws-sam-local package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     go-npm install
npm ERR! You can get their info via:
npm ERR!     npm owner ls aws-sam-local
npm ERR! There is likely additional logging output above.

> [email protected] preuninstall /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local
> go-npm uninstall


npm ERR! Please include the following file with any support request:
npm ERR!     /Users/sanathkr/workspace/GoWorkspace/src/github.com/awslabs/aws-sam-local/npm-debug.log

Invalid endpoint: https://kms..amazonaws.com (double dots)

Getting error Invalid endpoint: https://kms..amazonaws.com. Any idea where do I find endpoints.json to fix it. Is it part of lambci?

[DEBUG]	2017-08-16T16:31:58.586Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Looking for credentials via: env

[INFO]	2017-08-16T16:31:58.587Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Found credentials in environment variables.

[DEBUG]	2017-08-16T16:31:58.587Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Loading JSON file: /var/runtime/botocore/data/endpoints.json

[DEBUG]	2017-08-16T16:31:58.617Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Loading JSON file: /var/runtime/botocore/data/kms/2014-11-01/service-2.json

[DEBUG]	2017-08-16T16:31:58.620Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Loading JSON file: /var/runtime/botocore/data/_retry.json

[DEBUG]	2017-08-16T16:31:58.620Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Registering retry handlers for service: kms

[DEBUG]	2017-08-16T16:31:58.622Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Event creating-client-class.kms: calling handler <function add_generate_presigned_url at 0x7f50c4780bf8>

[DEBUG]	2017-08-16T16:31:58.623Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	Assuming an endpoint for kms, : https://kms..amazonaws.com

[DEBUG]	2017-08-16T16:31:58.623Z	4285aa19-3e63-42b5-83c4-17e8ddb10e09	The s3 config key is not a dictionary type, ignoring its value of: None

module initialization error: Invalid endpoint: https://kms..amazonaws.com
END RequestId: 4285aa19-3e63-42b5-83c4-17e8ddb10e09

Install docker along with the npm install script

Can we install Docker when we do npm install -g aws-sam-local? This will lead to an excellent user experience because customers don't have to install Docker as a prerequesite.

If not, we can at least point them to Docker download page and keep the installation paused, until they install Docker and press skip or continue.

"Amazon Kinesis" disambiguation

You may want to refer to "Amazon Kinesis Streams", both in the code and in the doc. Just because the sample event for Kinesis Firehose is slightly different.

Using SAM Local inside docker-compose

I currently am able to stand up an entire system of REST API microservices using docker-compose. These REST API microservices are written in all kinds of languages and frameworks, none of which are Lambda. This is necessary to run E2E testing for this given large scale application. The inability to use Lambda functions inside this large docker-compose file is the only thing that has stopped be from adding AWS Lambda to our microservices in the past.

SAM Local got super close to fulfilling this goal by at least allowing me to run AWS Lambda functions locally. However, due to the fact that it depends on docker-lambda, I cannot run a docker container inside another docker-container (or at least I really don't want to), so it's kind of a nonstarter.

What my question really boils down to is this:
At any point is it planned to be able to run SAM Local inside a docker container, without the major concerns that come along with running docker-in-docker?

sam local: --env-vars parameter does not work with "start-api" subcommand

Hi there,

When using this sample: https://aws.amazon.com/blogs/aws/new-aws-sam-local-beta-build-and-test-serverless-applications-locally/

If you try to use the environment variable file (--env-vars) in the command "sam local", it only works with the "invoke" if you try to use the "start-api" the variables are not loaded.

*Command1:

echo '{"httpMethod": "POST", "body": "{"vote": "spaces"}"}' |
sam local invoke "VoteSpacesTabs" --env-vars env.json

sam local invoke "VoteSpacesTabs" --env-vars env.json
2017/08/15 14:49:42 0.1.0
2017/08/15 14:49:42 Successfully parsed template.yaml (version 2010-09-09)
2017/08/15 14:49:42 Connected to Docker 1.30
2017/08/15 14:49:42 Fetching lambci/lambda:python3.6 image for python3.6 runtime...
python3.6: Pulling from lambci/lambda
Digest: sha256:66cbc36a528221efd64d5cbe2620a144a3f00172e6a444b36e2a1d975f0ae63c
Status: Image is up to date for lambci/lambda:python3.6
2017/08/15 14:49:46 Reading invoke payload from stdin (you can also pass it from file with --event)
2017/08/15 14:49:46 Invoking lambda_function.lambda_handler (python3.6)
START RequestId: 90f5d6db-6fef-4fb2-bce5-560e003e319f Version: $LATEST
dynamodb.Table(name='spaces-tabs-votes')
{'httpMethod': 'POST', 'body': '{"vote": "spaces"}'}
{'vote': 'spaces'}
END RequestId: 90f5d6db-6fef-4fb2-bce5-560e003e319f
REPORT RequestId: 90f5d6db-6fef-4fb2-bce5-560e003e319f Duration: 165 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 26 MB

{"body": "spaces now has 11 votes"}


*Command2 (and then, send a POST using curl):

sam local start-api --env-vars env.json

Error:
----- error ------
Parameter validation failed:
Invalid length for parameter TableName, value: 0, valid range: 3-inf: ParamValidationError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 36, in lambda_handler
ReturnValues='ALL_NEW'
File "/var/runtime/boto3/resources/factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "/var/runtime/boto3/resources/action.py", line 83, in call
response = getattr(parent.meta.client, operation_name)(**params)
File "/var/runtime/botocore/client.py", line 310, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 573, in _make_api_call
api_params, operation_model, context=request_context)
File "/var/runtime/botocore/client.py", line 628, in _convert_to_request_dict
api_params, operation_model)
File "/var/runtime/botocore/validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid length for parameter TableName, value: 0, valid range: 3-inf
----- error -----

Could you please take a look at it ?

Thank you.

Support for JSON

Doesn't appear to support JSON yet....

aws-sam-local validate -t sam_build.json 
2017/08/14 11:12:07 PANIC: YAML contains malformed structures
panic: PANIC: YAML contains malformed structures

To YAML or to YML?

By default, if no --template or -t parameter is provided, we default to template.yaml.

There is no real standard for whether to use .yaml or .yml and published toolings/projects/samples seem to be a mix.

We should make the default template.[yml|yaml] and make everybody's life a bit easier.

[Question] - SyntaxError when using Python, boto3 and s3

Apologies in advance if this is not the right place to open this issue, I don't have an extensive experience with aws-sam-local or Python, so I may be missing something really stupid.

I have a problem with my simple sam function; assuming that test.py and template.yaml are in the current folder, the issue can be reproduced by simply running echo '{}' | sam local invoke Test.

The error I get is SyntaxError: invalid syntax on line client = boto3.client('s3') - full history on https://gist.github.com/maoo/2175a1c4b75a80c7271943591afb4920#file-error-log

The interesting part is that running the same function without sam, everything works; assuming that test.py and template.yaml are in the current folder, you can test the following command...

pip install boto3 -t .
python -c 'from test import test1; test1(None,None)'

... which expects to return an error saying The specified key does not exist.

Support for AWS::Lambda::Function and AWS::ApiGateway::RestApi

When running aws-sam-local with a template file that uses AWS::Lambda::Function and AWS::ApiGateway::RestApi I see that aws-sam-local complains about missing Serverless functions and related API events. Can aws-sam-local work with AWS::Lambda::Function and AWS::ApiGateway::RestApi ?

validate does not return useful messages

Given a template:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  VoteSpacesTabs:
    Type: "AWS::Serverless::Function"
    Properties:
      Runtime: python3.6
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Environment:
        Variables:
          TABLE_NAME: !Ref VotesTable
      Events:
        Vote:
          Type: Api
          Properties:
            Path: /vote
            Method: post

Invoking:
sam validate
returns:
Valid!

Should it return valid given that we have no code-uri or other required attributes? What exactly is it validating?

Given this template:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  VotesTable:
    Type: "AWS::Serverless::SimpleTable"
  VoteSpacesTabs:
    Type: "AWS::Serverless::Function"
    Properties:
      Runtime: python3.6
      Handler: lambda_function.lambda_handler
      Policies: AmazonDynamoDBFullAccess
      Environment:
        Variables:
          TABLE_NAME: !Ref VotesTable
      Events:
        Vote:
          Type: Api
          Properties:
            Path: /vote
            Method: post

Invoking
sam validate
Returns:
ERROR: Failed to read the resources line numbers. This usually means that the template contains invalid indentation. Please check it and try again

This error message isn't helpful in determining what's wrong. I still haven't figured out what's wrong.

However both templates are valid from the point of view of cloudformation:
aws cloudformation validate-template --template-body file://template.yaml

Package to local

It appears sam can only package to S3. It would be nice if to package locally so we could leverage our existing CI process and tools for artifacts.

Failing to remote debug Python Lambda using pydevd

I've tried various combinations to get remote debugging to work, but so far I'm unsuccessful. In my environment I'm using a Mac with PyDev IDE. I start the PyDev debug server on port 5678. I can run a local Python script from the command line using pydevd and it connects to my debug server, and I'm able to remotely debug the code.

With 'sam local', I use the simple Lambda below, but it does not connect to my debug server in PyDev:

import pydevd

print('Loading function')

def handler(event, context):
    pydevd.settrace("0.0.0.0", port=5678)
    message = event['Records'][0]['Sns']['Message']
    print("From SNS: " + message)

Here is the output:

$ sam local invoke AirmileFunction --debug-port 5678 --template sam-airmile-with-stack-dependency.yml --event testSNSEvent.json 
2017/08/16 11:13:42 0.1.0
2017/08/16 11:13:42 Successfully parsed sam-airmile-with-stack-dependency.yml (version 2010-09-09)
2017/08/16 11:13:42 Connected to Docker 1.27
2017/08/16 11:13:42 Fetching lambci/lambda:python2.7 image for python2.7 runtime...
python2.7: Pulling from lambci/lambda
Digest: sha256:6df7061392bd2fe09b6422b24a821f4a98c799b071d5a080989e9dda8ce3ffe7
Status: Image is up to date for lambci/lambda:python2.7
2017/08/16 11:13:46 Invoking calc-airmile-lambda.handler (python2.7)
START RequestId: 602c0719-e605-4544-8307-275f2159d54a Version: $LATEST
warning: Debugger speedups using cython not found. Run '"/usr/bin/python2.7" "/var/task/setup_cython.py" build_ext --inplace' to build.
Loading function
Could not connect to 0.0.0.0: 5678
Traceback (most recent call last):
  File "/var/task/_pydevd_bundle/pydevd_comm.py", line 524, in start_client
    s.connect((host, port))
  File "/usr/lib64/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused

If I run the PyDev debug server first, I see the following error, so I run 'sam local' first, then start the debug server. The usual approach is to start the debug server first, then run the python script that connects to the debug server:

Bind for 0.0.0.0:5678 failed: port is already allocated

Invoking Local Lambda via AWS CLI and SDK

The ability to invoke sam local Lambda functions via the AWS CLI and SDK, by simply setting the endpoint. Today, you have to call sam local invoke to actually Invoke a Lambda function. This means, you can't port your existing integration tests that run both against the local Lambda environment and cloud.

SAM Local can provide a local HTTP endpoint that responds to Lambda Invoke API and invokes Lambda locally. You can simply point AWS CLI or SDK to this endpoint to run tests against it.

Validate Fails on AlexaSkillEvent

Repro:

git clone https://github.com/awslabs/serverless-application-model.git
cd serverless-application-model/examples/2016-10-31/alexa_skill
aws-sam-local validate template.yaml

File contents:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Alexa Skill https://developer.amazon.com/alexa-skills-kit
Resources:
  AlexaSkillFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: s3://<bucket>/alexa_skill.zip
      Handler: index.handler
      Runtime: nodejs4.3
      Events:
        AlexaSkillEvent:
          Type: AlexaSkill

output:

ERROR: Resource "AlexaSkillFunction", property "Events": Inner property Properties is required (line: 12; col: 8)

expected output: Success

Panic: Interface conversion error for BatchSize in Dynamodb Stream Event

Issue

When validating a template that contains a Dynamodb Stream Event with a BatchSize I get the following error: panic: interface conversion: interface {} is int, not string. The complete stack trace is added below.

Reproduce

The following example yaml file (from AWS examples under Events) gives me the same error:

# template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  FunctionName:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      Events:
        Stream:
          Type: DynamoDB
          Properties:
            Stream: !GetAtt DynamoDBTable.StreamArn
            BatchSize: 100
            StartingPosition: TRIM_HORIZON 

Run:

$ sam validate

Output:

$ sam validate
2017/08/14 10:37:51 0.1.0
panic: interface conversion: interface {} is int, not string

goroutine 1 [running]:
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.scaffoldEventSourceMap(0x196b820, 0xc4204eb950, 0x1675e2d)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function-event-source.go:102 +0x6c6
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*functionTemplate).Scaffold(0xc420116000, 0x196b860, 0xc42029f7e0, 0x0, 0x0, 0xe, 0x168b7c4, 0x26, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:160 +0x583
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*awsServerlessFunction).Scaffold(0x19bcdc0, 0x196b860, 0xc42029f7e0, 0x0, 0x0, 0x26, 0x0, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:80 +0x6a
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*awsServerlessFunction).ClassConstructor(0x19bcdc0, 0x196b860, 0xc42029f7e0, 0x0, 0x0, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:61 +0x55
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.postProcess(0x196e4e0, 0xc42028a320, 0x196e4e0, 0xc42028a320, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/post-process.go:46 +0x533
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Parse(0xc42039d200, 0x19a, 0x600, 0x19a, 0x600, 0x0, 0x0, 0xc42000c050, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:72 +0x407
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.read(0x1966360, 0xc42000c050, 0xc42000c050, 0x0, 0x0, 0x0, 0x1, 0x1)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:40 +0x105
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Open(0xc4201b3119, 0xd, 0xc4201b3119, 0xd, 0x13, 0x0, 0x0, 0xc420310f90)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:29 +0x27e
main.validate(0xc420172640)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/validate.go:13 +0x7a
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.HandleAction(0x1587e60, 0x169a720, 0xc420172640, 0xc42043c900, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:487 +0x7c
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.Command.Run(0x1677894, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x16971ee, 0xa7, 0x0, ...)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/command.go:207 +0xb72
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.(*App).Run(0xc42046d040, 0xc42000a280, 0x2, 0x2, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:250 +0x7d0
main.main()
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/main.go:302 +0x1be1

Fix

When I change BatchSize: 100 to BatchSize: '100' the template is found valid.

$ sam validate
2017/08/14 10:38:01 0.1.0
Valid!

Further digging

$ aws cloudformation validate-template doesn't care about whether BatchSize is a string or an integer.
I hope this is enough information, let me know I can supply you with anything else!

Assistance troubleshooting sam local invoke

I'm trying to use sam local invoke to simulate an S3 event. When I try and run the sam local invoke command "sam local invoke -e event.json --debug-port 5858 ExampleFunction"

I get an error message
"unable to use container host config override file from '$HOME/.config/aws-sam-local/container-config.json': HOME env variable is not set"

Where should the HOME environment variable be set? I assume I'm doing something silly....

aws-sam-local for aws-serverless-java-container not working

I want to mock API Gateway of jersey java project, which is like aws-serverless-java-container provided by awslabs.

I developed my serverless application in reference to for the jersey project sample.
But when I apply aws-sam-local to my application, it did not worked.

So I tried to apply the aws-sam-local to sample project. But it did not also worked.
My operation is as follows.

$ sam --version
sam version 0.1.1

$ git clone https://github.com/awslabs/aws-serverless-java-container
$ cd aws-serverless-java-container/samples/jersey/pet-store
$ mvn package
$ cp sam.yaml template.yaml
$ sam validate
Valid!
$ sam local start-api
2017/08/17 10:32:40 Connected to Docker 1.30
2017/08/17 10:32:40 Successfully parsed template.yaml (version 2010-09-09)
2017/08/17 10:32:40 Fetching lambci/lambda:java8 image for java8 runtime...
java8: Pulling from lambci/lambda
Digest: sha256:668979530863a155b52533947e782fe164908eda2d6c5741317511bfa036d8cf
Status: Image is up to date for lambci/lambda:java8

Mounting com.amazonaws.serverless.sample.jersey.LambdaHandler::handleRequest (java8) at http://127.0.0.1:3000/{proxy+} [OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT]

You can now browse to the above endpoints to invoke your functions.
You do not need to restart/reload SAM CLI while working on your functions,
changes will be reflected instantly/automatically. You only need to restart
SAM CLI if you update your AWS SAM template.

It seems like mocking API Gateway successfully.
But when I tried to call api, it doesn't return exepected response.

$ curl http://127.0.0.1:3000/pets
{ "message": "Internal server error" }%

And the logs about the api call is as follows.

2017/08/17 10:32:58 Invoking com.amazonaws.serverless.sample.jersey.LambdaHandler::handleRequest (java8)

Do you have any idea why the internal server error caused ?

Support for serving static files

If you are building a serverless website, Static files like Javascript, HTML or PNG are usually uploaded to S3 in a separate build step. This works when you are deploying and running code in Lambda. But when using SAM Local, you need these resources served by SAM Local CLI

Ex:
localhost:3000 -> serves the index.html
localhost:3000/myfile.js -> should serve Javascript
localhost:3000/static/image.png -> should serve images

Today, the only endpoint exposed via SAM Local are the APIs configured in your SAM file. This is not sufficient. We need to support serving static files from the directory where their Lambda function is mounted.

Proposal:
If a route is not found, before returning 404, have SAM Local check pwd or Lambda function's mount directory for static files matching the name/path. If found, return the file. Otherwise return 404. This will give you static file capabilities right out of the box, without any extra work.

We can expose --public-dir parameter to specify path to search for static files.

yaml validation fails for functions with dash in name

The following works fine:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
  FunctionName:
      Type: 'AWS::Serverless::Function'
      Properties:
        Handler: index.handler
        Runtime: nodejs6.10

But when the function name contains a dash, it produces an error:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
  Function-Name:
      Type: 'AWS::Serverless::Function'
      Properties:
        Handler: index.handler
        Runtime: nodejs6.10
ERROR: Failed to read the resources line numbers. This usually means that the template contains invalid indentation. Please check it and try again

Missing Makefile?

CONTRIBUTING.md says:

You may run all test by either running the make test target (requires go, and go cover to be installed).

But there's no Makefile so make test just exits with:

make: Nothing to be done for `test'.`

No binary installed with yarn

The yarn install succeeds, but there's no binary:

/ # yarn global add aws-sam-local
yarn global v0.27.5
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
warning "[email protected]" has no binaries
warning No license field
Done in 8.92s.
/ # sam --version
/bin/sh: sam: not found

I believe it would be good to get working with yarn just because I've seen far fewer problems with global installs with yarn vs npm (especially npm@5 โ€“ it still has some teething problems)

Sample codes local api return Internal server error

When I run the sample codes about API Gateway https://github.com/awslabs/aws-sam-local/tree/master/samples/api-event-source

I have unexpected error in the response.
Firstly run the API with sam local start-api

2017/08/23 13:11:45 Connected to Docker 1.30
2017/08/23 13:11:45 Successfully parsed template.yml
2017/08/23 13:11:45 Fetching lambci/lambda:nodejs6.10 image for nodejs6.10 runtime...
nodejs6.10: Pulling from lambci/lambda
Digest: sha256:4e6a92d033a1a1e0c580bc66caea4a892256479c611cecafa19e6e29e2a9cb62
Status: Image is up to date for lambci/lambda:nodejs6.10

Mounting static files from /Users/ktb-ot226/ktbo/python/nodeSAM at /
Mounting index.handler (nodejs6.10) at http://127.0.0.1:3000/ [OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT]

You can now browse to the above endpoints to invoke your functions.
You do not need to restart/reload SAM CLI while working on your functions,
changes will be reflected instantly/automatically. You only need to restart
SAM CLI if you update your AWS SAM template.

then execute this curl http://localhost:3000/ and response

{ "message": "Internal server error" }

the api local show

2017/08/23 13:15:38 Invoking index.handler (nodejs6.10)
START RequestId: f0f4521f-1762-114c-0feb-6aad5e501abc Version: $LATEST
2017-08-23T18:15:42.820Z	f0f4521f-1762-114c-0feb-6aad5e501abc	TEST
END RequestId: f0f4521f-1762-114c-0feb-6aad5e501abc
REPORT RequestId: f0f4521f-1762-114c-0feb-6aad5e501abc	Duration: 6.37 ms	Billed Duration: 0 ms	Memory Size: 0 MB	Max Memory Used: 28 MB
2017/08/23 13:15:49 Function index.handler timed out after 3 seconds

I don't know why if the correct response is

"This is a LIST operation, return all products"

I have sam version 0.2.0 and Docker version 17.06.1-ce, build 874a737

Any idea?

panic: interface conversion: interface {} is map[interface {}]interface {}, not string

Issue

When validating a template that contains a 'AWS::Serverless::Function' with a Policies property I get the following error:

2017/08/16 15:08:57 0.1.0
panic: interface conversion: interface {} is map[interface {}]interface {}, not string

goroutine 1 [running]:
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.safeProcessStringArray(0x196b820, 0xc420236cf0, 0x167733c, 0x8, 0xc4204c9048)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/safe-processing.go:46 +0x15f
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*functionTemplate).Scaffold(0xc4201380b0, 0x196b860, 0xc4202a8f20, 0x0, 0x0, 0xe, 0x168b7c4, 0x26, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:146 +0x3bf
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*awsServerlessFunction).Scaffold(0x19bcdc0, 0x196b860, 0xc4202a8f20, 0x0, 0x0, 0x26, 0x0, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:80 +0x6a
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*awsServerlessFunction).ClassConstructor(0x19bcdc0, 0x196b860, 0xc4202a8f20, 0x0, 0x0, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:61 +0x55
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.postProcess(0x196e4e0, 0xc420448a00, 0x196e4e0, 0xc420448a00, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/post-process.go:46 +0x533
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Parse(0xc420312000, 0xc4e, 0x1e00, 0xc4e, 0x1e00, 0x0, 0x0, 0xc42000c050, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:72 +0x407
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.read(0x1966360, 0xc42000c050, 0xc42000c050, 0x0, 0x0, 0x0, 0x1, 0x1)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:40 +0x105
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Open(0xc4202ab02e, 0xd, 0xc4202ab02e, 0xd, 0x13, 0x0, 0x0, 0xc4202dcf90)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:29 +0x27e
main.validate(0xc42041b040)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/validate.go:13 +0x7a
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.HandleAction(0x1587e60, 0x169a720, 0xc42041b040, 0xc42006ea00, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:487 +0x7c
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.Command.Run(0x1677894, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x16971ee, 0xa7, 0x0, ...)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/command.go:207 +0xb72
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.(*App).Run(0xc420338820, 0xc42000e240, 0x3, 0x3, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:250 +0x7d0
main.main()
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/main.go:302 +0x1be1

Reproduce

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
  FunctionName:
      Type: 'AWS::Serverless::Function'
      Properties:
        Handler: index.handler
        Runtime: nodejs6.10
        Policies:
          - Effect: Allow
            Action:
              - 'dynamodb:*'
            Resource: '*'

Remove the policies property and sam validate succeeds.

Looks related to #35

Headers in local start-api event should start with lowercase

Event generated by api gateway has headers key in lowercase. One generated by local api has Headers in camelcase.

"resource": "/{api+}",
    "path": "/testapi1",
    "httpMethod": "GET",
    "headers": {
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Encoding": "gzip, deflate, sdch, br",
        "Accept-Language": "en-GB,en-US;q=0.8,en;q=0.6",
"Headers": {"Accept": "application/json", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,hi-IN;q=0.8,hi;q=0.6,en;q=0.4",  

Validation fails on !Join

Hi

I have a SAM template that works fine when I deploy via the AWS cli using aws cloudformation package and deploy. However it fails via sam. I get the following validation error.

2017/08/12 21:08:31 0.1.0
2017/08/12 21:08:31 ERROR: did not find expected ',' or ']' (line: 7; col: 0)

The line in question has a !Join. Like the following:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: CRUD service
Outputs:
ApiUrl:
Description: URL of API endpoint
Value: !Join ['', ['https://', !Ref "MyApi", '.execute-api.', !Ref 'AWS::Region', '.amazonaws.com/Prod']]

I've omitted the remainder of the template for brevity.

Support for Lambda integration

The README mentions aws-sam-local uses Lambda proxy integration by default. Is there a way to tell aws-sam-local to use Lambda integration instead?

[python] 3rd party modules

currently, for 3rd party module, we have to do pip install -t . on the same directory as template.yaml and the main python application file. This pollutes the working directory when you have a lot of modules. Is there a better way to handle this?
maybe on the file zipping of a subdirectory?

Context object invoked_arn incomplete

In Lambda I extract the region the function is running in for various purposes (mostly for creating a boto3 sessions for building clients, assuming roles etc).

eg:

def determine_region(context):

    m = re.match("arn:aws:lambda:(.*?):\d+.*$", context.invoked_function_arn)
    if m:
        return(m.group(1))

SAM Local doesn't appear to include a region in the arn. I get something like:
arn:aws:lambda::104260451092:function:test

I haven't found anywhere I can set the region for the context object in the template.yaml file. Have I missed something?

Thanks!

generate-event api produces malformed json

sorry, wanted to raise a warning, but can't figure out how to fix and submit a PR

observed:

%> sam local generate-event api | head -3
{
  "body": "{ "test\": \"body\"}",
  "resource": "/{proxy+}",

expected:

%> sam local generate-event api | head -3
{
  "body": "{ \"test\": \"body\"}",
  "resource": "/{proxy+}",

create .: volume name is too short, names should be at least two alphanumeric characters

When I am trying to run function locally I got error form docker:

sam local invoke "HelloWorldFunction" -e index.js
2017/08/12 13:03:27 0.1.0
2017/08/12 13:03:27 Successfully parsed template.yaml (version 2010-09-09)
2017/08/12 13:03:27 Connected to Docker 1.30
2017/08/12 13:03:27 Fetching lambci/lambda:nodejs4.3 image for nodejs4.3 runtime...
nodejs4.3: Pulling from lambci/lambda
Digest: sha256:1ec74ee2e5c71e231d87d9b961f4f310bf817088f4391763a37e5adb657c6038
Status: Image is up to date for lambci/lambda:nodejs4.3
2017/08/12 13:03:30 Invoking index.handler (nodejs4.3)
2017/08/12 13:03:30 Could not invoke function: Error response from daemon: create .: volume name is too short, names should be at least two alphanumeric characters

Some info about my local system:

docker -v
Docker version 17.06.0-ce, build 02c1d87
docker-compose -v
docker-compose version 1.14.0, build c7bdf9e

OS

ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G29

pls let me know in case if you need more info

Expecting "int", got "string" on property Timeout on Lambda Function

I'm receiving an error when providing a Timeout via a !Ref

The resource I'm receiving the error on:

 CustomAuthorizerLambdaFunction:
   Type: AWS::Serverless::Function
   Properties:
     CodeUri: ./code.jar
     Handler: someClass
     Runtime: java8
     Timeout: !Ref FunctionTimeout
     VpcConfig:
       SecurityGroupIds:
         - !Ref LambdaVPCSecurityGroup
       SubnetIds: !Ref Subnets
     MemorySize: 512
     Environment:
       Variables:
         REDIS_HOST: !Ref RedisHost
         REDIS_PORT: "6379"
         DEFAULT_DB_TIMEOUT: !Ref DBIdleTimeout
     Policies:
       - AWSLambdaVPCAccessExecutionRole
       - AWSXrayWriteOnlyAccess
     Tags:
       Department: engineering
       Application: customer-api
       Service: authorizer-processing

the error I receive:

ERROR: Resource "CustomAuthorizerLambdaFunction", property "Timeout": Expecting "int", got "string" (line: 278; col: 6)

'Invalid endpoint' when Lambda invokes DynamoDB

When my Lambda instantiates a boto3 session to the dynamoDB service, it fails with Invalid endpoint: https://dynamodb..amazonaws.com. Note the missing region in the URI (see stack trace below).

    dynamodb = boto3.resource('dynamodb')

I can force this to work by specifying a region:

    dynamodb = boto3.resource('dynamodb', region_name='ap-northeast-1' )

I cannot use the region in the Lamba env as it is blank:

    dynamodb = boto3.resource('dynamodb', region_name=os.environ['AWS_DEFAULT_REGION'] )

Lambda environment variables:

lambda env:

{'_HANDLER': 'calc-airmile-lambda.handler', 'AWS_LAMBDA_FUNCTION_VERSION': '$LATEST', 'LAMBDA_TASK_ROOT': '/var/task', 'AWS_REGION': '', 'LAMBDA_RUNTIME_DIR': '/var/runtime', 'PYTHONPATH': '/var/runtime', 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE': '128', 'AWS_LAMBDA_FUNCTION_TIMEOUT': '3', 'AWS_DEFAULT_REGION': '', 'AWS_SAM_LOCAL': 'true', 'HOSTNAME': 'd479d39ddb0a', etc.}

Stack trace

Invalid endpoint: https://dynamodb..amazonaws.com: ValueError
Traceback (most recent call last):
  File "/var/task/calc-airmile-lambda.py", line 30, in handler
    dynamodb = boto3.resource('dynamodb', region_name=os.environ['AWS_DEFAULT_REGION'] )
  File "/var/runtime/boto3/__init__.py", line 92, in resource
    return _get_default_session().resource(*args, **kwargs)
  File "/var/runtime/boto3/session.py", line 389, in resource
    aws_session_token=aws_session_token, config=config)
  File "/var/runtime/boto3/session.py", line 263, in client
    aws_session_token=aws_session_token, config=config)
  File "/var/runtime/botocore/session.py", line 836, in create_client
    client_config=config, api_version=api_version)
  File "/var/runtime/botocore/client.py", line 71, in create_client
    verify, credentials, scoped_config, client_config, endpoint_bridge)
  File "/var/runtime/botocore/client.py", line 281, in _get_client_args
    verify, credentials, scoped_config, client_config, endpoint_bridge)
  File "/var/runtime/botocore/args.py", line 79, in get_client_args
    timeout=(new_config.connect_timeout, new_config.read_timeout))
  File "/var/runtime/botocore/endpoint.py", line 273, in create_endpoint
    raise ValueError("Invalid endpoint: %s" % endpoint_url)
ValueError: Invalid endpoint: https://dynamodb..amazonaws.com

did not find expected alphabetic or numeric character

Hi,
I'm having an issue with the sam local start-api and sam validate commands.

Installed with npm on OSX.

Versions:

  • OSX 10.12.6
  • Docker 17.06.0-ce-mac19 (18663)
  • nvm 0.33.2
  • npm 3.10.10
  • node v6.11.2

Should be able to reproduce with a template.yml like this:

AWSTemplateFormatVersion: '2010-09-09'
Transform: "AWS::Serverless-2016-10-31"

Resources:
  Api:
    Type: "AWS::Serverless::Api"
    Properties:
      DefinitionUri: ./swagger.yml
      StageName: prod
      Variables:
        ModelsFunctionName: !Ref ModelsFunction

  ModelsFunction:
    Type: "AWS::Serverless::Function"
    Properties:
      CodeUri: lambdas/models
      Handler: models.lambda_handler
      Runtime: python3.6
      Environment:
        Variables:
          S3Bucket: !Ref S3Bucket
      Events:
        CreateModel:
          Type: Api
          Properties:
            Path: /models
            Method: POST
            RestApiId: !Ref Api
      Policies:
        -
          Version: "2012-10-17"
          Statement:
            -
              Effect: Allow
              Action:
                - "s3:*"
              Resource:
                - !Sub "arn:aws:s3:::${S3Bucket}"
                - !Sub "arn:aws:s3:::${S3Bucket}/*"

  S3Bucket:
    Type: "AWS::S3::Bucket"
    Properties:
      BucketName: !Sub "foo-${AWS::StackName}-${AWS::Region}-${AWS::AccountId}"

This gets me the following error:

> sam validate
2017/08/16 12:03:37 0.1.0
ERROR:  did not find expected alphabetic or numeric character (line: 38; col: 0)

line 52 is:

                - !Sub "arn:aws:s3:::${S3Bucket}"

YAML file is space indented.

Cloudformation Templates

Is there a way to use this with functions using AWS::Lambda::Function or it is only AWS::Serverless::Function?

Flag to disable pulling new Docker container and reuse cached container

Currently SAM CLI pulls new Docker container every time you run. If no new Docker container version exists, it will use the cached container. Otherwise it will start downloading the container which can be slow when you have bad internet or lead to bad experience when you are demo-ing the tool.

Provide a flag to disable docker container version check and use the cached container.

support packaged CodeUri

Our SAM template references a zip file CodeUri as our stuff is compiled prior to deployment but aws-sam-local doesn't handle this very well. Ie CodeUri: ../target/lambda.zip

Error:

 Could not invoke function: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/home/myuser/lambda-code/target/lambda.zip\\\" to rootfs \\\"/var/lib/docker/overlay2/ef772db7acbb72271b6e24b4af6937a30adfa608d595aeae6fa2411f586d11fd/merged\\\" at \\\"/var/lib/docker/overlay2/ef772db7acbb72271b6e24b4af6937a30adfa608d595aeae6fa2411f586d11fd/merged/var/task\\\" caused \\\"not a directory\\\"\""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.