Skip to content

Commit

Permalink
Merge pull request #89 from arothian/sam_fixes
Browse files Browse the repository at this point in the history
Update SAM transform to handle ReservedConcurrentExecutions parameter
  • Loading branch information
Kevin Formsma authored Apr 21, 2021
2 parents 5d7dcd8 + e51fe56 commit c595f34
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/gempush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ jobs:
commit:
name: Commit
runs-on: ubuntu-latest
strategy:
fail-fast: false # Allows both ruby versions to run before failing
matrix:
ruby: ['2.5', '3.0']

steps:
- uses: actions/checkout@master
- name: Set up Ruby 2.5
uses: actions/setup-ruby@v1
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5.x
- name: Install Bundler
run: gem install bundler
- name: Which bundler?
run: bundle -v
- name: Bundle install
run: bundle check || bundle install
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
#- name: Rubocop lint
# run: bundle exec rubocop -D
- name: Rspec tests
Expand All @@ -44,7 +43,7 @@ jobs:
rubygems_api_key: ${{secrets.rubygems_api_key}}
- name: Create release with changelog
id: gh_release
uses: release-drafter/release-drafter@f677696
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
5 changes: 5 additions & 0 deletions lib/cfn-model/transforms/serverless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def serverless_function_properties(cfn_hash, serverless_function, fn_name, with_
handler: serverless_function_property(serverless_function, cfn_hash, 'Handler'),
role: format_function_role(serverless_function, fn_name),
runtime: serverless_function_property(serverless_function, cfn_hash, 'Runtime'),
reserved_concurrent_executions: serverless_function_property(serverless_function, cfn_hash, 'ReservedConcurrentExecutions'),
with_line_numbers: with_line_numbers
}

Expand All @@ -118,6 +119,7 @@ def replace_serverless_function(cfn_hash, resource_name, with_line_numbers)
code_key: lambda_fn_params[:code_key],
role: lambda_fn_params[:role],
runtime: lambda_fn_params[:runtime],
reserved_concurrent_executions: lambda_fn_params[:reserved_concurrent_executions],
with_line_numbers: lambda_fn_params[:with_line_numbers]
)
unless serverless_function['Properties']['Role']
Expand Down Expand Up @@ -223,6 +225,7 @@ def lambda_function(handler:,
code_key: nil,
role:,
runtime:,
reserved_concurrent_executions:,
with_line_numbers: false)
fn_resource = {
'Type' => format_resource_type('AWS::Lambda::Function', -1, with_line_numbers),
Expand All @@ -232,6 +235,8 @@ def lambda_function(handler:,
'Runtime' => runtime
}
}
fn_resource['Properties']['ReservedConcurrentExecutions'] = reserved_concurrent_executions unless reserved_concurrent_executions.nil?

lambda_function_code(fn_resource, code_bucket, code_key)
end

Expand Down
1 change: 1 addition & 0 deletions spec/test_templates/yaml/sam/globals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Resources:
FunctionName: !Sub "${Site}-Function"
Handler: "com.test.Function::handleRequest"
Tracing: Active
ReservedConcurrentExecutions: 1
Tags:
warmup: True
7 changes: 7 additions & 0 deletions spec/transforms/serverless_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
).to(
eq 'AWS::Lambda::Function'
)
expect(
actual_cfn_model.raw_model['Resources']['MyServerlessFunctionLogicalID']['Properties']
).not_to include('ReservedConcurrentExecutions')
expect(
actual_cfn_model.raw_model['Resources']['MyServerlessFunctionLogicalID'].key?('Metadata')
).to be false
Expand Down Expand Up @@ -92,6 +95,10 @@
global_endpoint_configuration = actual_cfn_model.globals['Api'].endpointConfiguration
global_runtime = actual_cfn_model.globals['Function'].runtime

expect(
actual_cfn_model.raw_model['Resources']['SomeFunction']['Properties']
).to include('ReservedConcurrentExecutions')

expect(actual_bucket).to eq expected_bucket
expect(actual_key).to eq expected_key
expect(actual_runtime).to eq expected_runtime
Expand Down

0 comments on commit c595f34

Please sign in to comment.