-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Ruby to Supported Runtime Enum #866
Changes from all commits
dfbd903
b2cdfde
ac35ac2
ee51bb4
f8988c3
b79f2fd
381a7c5
98cf7b0
24a3aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "httparty" | ||
|
||
group :test do | ||
gem "test-unit" | ||
gem "mocha" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ This is a sample template for {{ cookiecutter.project_name }} - Below is a brief | |
├── README.md <-- This instructions file | ||
├── hello_world <-- Source code for a lambda function | ||
│ ├── app.rb <-- Lambda function code | ||
├── Gemfile <-- Ruby dependencies | ||
│ ├── Gemfile <-- Ruby function dependencies | ||
├── Gemfile <-- Ruby test/documentation dependencies | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a huge fan of the Double There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So...I'm open to ways we can support this through It's actually very possible that multiple Gemfiles may be a reality, and that we just need to teach the paradigm. Why?
There is actually precedent for this, the Ruby SDK repo itself: https://github.com/aws/aws-sdk-ruby/ We have a global Gemfile for testing, building, and documentation generation. Within each modular package, we have its own gemspec for only the required dependencies. This may be the correct pattern for modular Lambda functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can image an appropriate alternative approach, perhaps where we use "groups" per function to keep dependency versions in sync in a global Gemfile. In an ideal world, we could provide options to the user. |
||
├── template.yaml <-- SAM template | ||
└── tests <-- Unit tests | ||
└── unit | ||
|
@@ -31,27 +32,27 @@ Setup Ruby Version Manager from [Ruby Version Manager](http://rvm.io/) | |
Run following commands | ||
|
||
```bash | ||
rvm install ruby-2.5.0 | ||
rvm use ruby-2.5.0 | ||
rvm --default use 2.5.0 | ||
rvm install ruby-2.5.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does patch version need to be specified here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a best practice, yes. Ruby on AWS Lambda uses version 2.5.3 - while 2.5.0 will technically work for builds, there are security patches present on 2.5.3 that are not present on 2.5.0, so I would not intentionally direct users to use an older version in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way the newest just gets installed. I am worried this will be out of date and something we need to maintain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to provide instructions on how to use install Ruby for Ruby developers? I wonder if Requirements (ruby 2.5) suffices as we do with Python and Node init There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how you install Ruby. Not sure what the question is @heitorlessa There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, let me try once more and let me know if it's clearer:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't add install instructions. People who use languages like ruby, go etc will have their tooling in place. It would be like every pkg internally saying start off by installing the Amazon builder tools. |
||
rvm use ruby-2.5.3 | ||
rvm --default use 2.5.3 | ||
``` | ||
|
||
### Building the Project | ||
|
||
### Installing dependencies | ||
```sam-app``` comes with a Gemfile that defines the requirements and manages installing them. The `sam build` command will install the dependencies in your function Gemfile and vendor it for deployment. | ||
|
||
```sam-app``` comes with a Gemfile that defines the requirements and manages installing them. | ||
|
||
```bash | ||
gem install bundler | ||
bundle install | ||
bundle install --deployment --path hello_world/vendor/bundle | ||
``` | ||
sam build | ||
``` | ||
|
||
* Step 1 installs ```bundler```which provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. | ||
* Step 2 creates a Gemfile.lock that locks down the versions and creates the full dependency closure. | ||
* Step 3 installs the gems to ```hello_world/vendor/bundle```. | ||
If your dependencies contain native modules that need to be compiled specifically for the operating system running on AWS Lambda, use this command to build inside a Lambda-like Docker container instead: | ||
|
||
**NOTE:** As you change your dependencies during development you'll need to make sure these steps are repeated in order to execute your Lambda and/or API Gateway locally. | ||
``` | ||
sam build --use-container | ||
``` | ||
By default, this command writes built artifacts to .aws-sam/build folder. | ||
|
||
**NOTE:** As you change your dependencies during development you'll need to run `sam build` again in order to execute your Lambda and/or API Gateway locally. | ||
|
||
### Local development | ||
|
||
|
@@ -124,20 +125,18 @@ aws cloudformation describe-stacks \ | |
|
||
## Testing | ||
|
||
We use [Mocha](http://gofreerange.com/mocha/docs) for testing our code and you can install it using gem: ``gem install mocha`` | ||
|
||
Next, we run our initial unit tests: | ||
Run our initial unit tests: | ||
|
||
```bash | ||
ruby tests/unit/test_hello.rb | ||
ruby tests/unit/test_handler.rb | ||
``` | ||
|
||
**NOTE**: It is recommended to use a Ruby Version Manager to manage, and work with multiple ruby environments from interpreters to sets of gems | ||
# Appendix | ||
|
||
## AWS CLI commands | ||
|
||
AWS CLI commands to package, deploy and describe outputs defined within the cloudformation stack: | ||
AWS CLI commands to package, deploy and describe outputs defined within the cloudformation stack after building: | ||
|
||
```bash | ||
sam package \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "httparty" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -630,7 +630,7 @@ def make_service(list_of_routes, function_provider, cwd): | |
|
||
def make_service_response(port, method, scheme, resourcePath, resolvedResourcePath, pathParameters=None, | ||
body=None, headers=None, queryParams=None, isBase64Encoded=False): | ||
response_str = '{"httpMethod": "GET", "body": null, "resource": "/something/{event}", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/something/{event}", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/something/{event}"}, "queryStringParameters": null, "headers": {"Host": "0.0.0.0:33651", "User-Agent": "python-requests/2.20.0", "Accept-Encoding": "gzip, deflate", "Accept": "*/*", "Connection": "keep-alive"}, "pathParameters": {"event": "event1"}, "stageVariables": null, "path": "/something/event1", "isBase64Encoded": false}' # NOQA | ||
response_str = '{"httpMethod": "GET", "body": null, "resource": "/something/{event}", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/something/{event}", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/something/{event}"}, "queryStringParameters": null, "headers": {"Host": "0.0.0.0:33651", "User-Agent": "python-requests/2.20.1", "Accept-Encoding": "gzip, deflate", "Accept": "*/*", "Connection": "keep-alive"}, "pathParameters": {"event": "event1"}, "stageVariables": null, "path": "/something/event1", "isBase64Encoded": false}' # NOQA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grrr.. let's just pin requests. We have installers now, so pinning isn't as dangerous. If customers run into conflicts, this gives them a reason to get onto our installers and out of pip (which is what we want/recommend anyways) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could remove requests from test requirements (dev.txt) , and pin the requests in the base.txt. But if we pin, we would periodically need to bump up requests as when there is a release of requests. |
||
response = json.loads(response_str) | ||
|
||
if body: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "httparty" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woot! sam build for ruby! :)