Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/pip/requirements/develop/refer…
Browse files Browse the repository at this point in the history
…encing-0.31.0
  • Loading branch information
hnnasit authored Nov 21, 2023
2 parents 9b52f81 + d5f7ba5 commit 957d8bb
Show file tree
Hide file tree
Showing 52 changed files with 72 additions and 67 deletions.
19 changes: 12 additions & 7 deletions samcli/lib/utils/async_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""
Contains asyncio related methods and helpers
"""
import asyncio
import logging
from asyncio import AbstractEventLoop, gather, new_event_loop
from concurrent.futures.thread import ThreadPoolExecutor
from functools import partial
from typing import Callable, List, Optional

LOG = logging.getLogger(__name__)


async def _run_given_tasks_async(tasks, event_loop=asyncio.get_event_loop(), executor=None):
async def _run_given_tasks_async(
tasks: List[Callable], event_loop: AbstractEventLoop, executor: Optional[ThreadPoolExecutor] = None
) -> list:
"""
Given list of Task objects, this method executes all tasks in the given event loop (or default one)
and returns list of the results.
Expand Down Expand Up @@ -50,7 +53,7 @@ async def _run_given_tasks_async(tasks, event_loop=asyncio.get_event_loop(), exe

LOG.debug("Waiting for async results")

for result in await asyncio.gather(*async_tasks, return_exceptions=True):
for result in await gather(*async_tasks, return_exceptions=True):
# for each task, wait for them to complete
if isinstance(result, Exception):
LOG.debug("Exception raised during the execution")
Expand All @@ -68,7 +71,9 @@ async def _run_given_tasks_async(tasks, event_loop=asyncio.get_event_loop(), exe
return results


def run_given_tasks_async(tasks, event_loop=asyncio.get_event_loop(), executor=None):
def run_given_tasks_async(
tasks: List[Callable], event_loop: AbstractEventLoop, executor: Optional[ThreadPoolExecutor] = None
) -> list:
"""
Runs the given list of tasks in the given (or default) event loop.
This function will wait for execution to be completed
Expand Down Expand Up @@ -99,7 +104,7 @@ def __init__(self):
self._async_tasks = []
self.executor = None

def add_async_task(self, function, *args):
def add_async_task(self, function: Callable, *args) -> None:
"""
Add a function definition and its args to the the async context, which will be executed later
Expand All @@ -111,7 +116,7 @@ def add_async_task(self, function, *args):
"""
self._async_tasks.append(partial(function, *args))

def run_async(self, default_executor=True):
def run_async(self, default_executor: bool = True) -> list:
"""
Will run all collected functions in async context, and return their results in order
Expand All @@ -124,7 +129,7 @@ def run_async(self, default_executor=True):
-------
List of result of the executions in order
"""
event_loop = asyncio.new_event_loop()
event_loop = new_event_loop()
if not default_executor:
with ThreadPoolExecutor() as self.executor:
return run_given_tasks_async(self._async_tasks, event_loop, self.executor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Resources:
- "LambdaExecutionRole"
- "Arn"
Code: "."
Runtime: nodejs10.x
Runtime: nodejs18.x
Timeout: 25
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/Contact-Us-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 345c4115-4060-43bd-be8e-7f70aee9b3bf
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
PostEvent:
Type: Api
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/DVSA-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ Resources:
- Ref: AWS::AccountId
- function:*
Version: '2012-10-17'
Runtime: nodejs10.x
Runtime: nodejs18.x
Timeout: 30
Type: AWS::Serverless::Function
OrderNewFunction:
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke/templates/sar/Geocode-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Resources:
Path: /geocode/{searchtext}
Type: Api
Handler: geocode.geocodeGET
Runtime: nodejs10.x
Runtime: nodejs18.x
Type: AWS::Serverless::Function
GeocodeSuggestFunction:
Properties:
Expand All @@ -52,6 +52,6 @@ Resources:
Path: /geocodesuggest/{query}
Type: Api
Handler: geocodesuggest.geocodesuggestGET
Runtime: nodejs10.x
Runtime: nodejs18.x
Type: AWS::Serverless::Function
Transform: AWS::Serverless-2016-10-31
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Key: 72571b00-7b1e-4e28-bf57-6bbd36bb70d0
Handler: index.handler
Description: Episode 4 - customise your leaderboard for the Echo Show and Spot
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
AlexaSkillEvent:
Type: AlexaSkill
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Key: f8b0837c-e68a-41d5-ab0a-13b1071b7c56
Handler: index.handler
Description: Demonstrate a basic trivia skill built with the ASK NodeJS SDK
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
AlexaSkillEvent:
Type: AlexaSkill
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/alexa-anagram-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Resources:
Properties:
Description: Alexa responds with the count and anagrams for a requested word
Handler: src/index.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: a44a03c9-ccb1-4ddc-b196-8e2c9fdeec35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: cc257676-15a1-4bb3-98eb-a0bdf0b46ca1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 947732d3-cec1-4e80-9596-37206a195f9d
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 128
Events:
AlexaTrigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: a3adadbb-f261-42e4-a1cc-5a83f2a7e052
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 128
Policies:
- Statement:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 5eb72e41-efab-405a-a429-ac765d3c08ca
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 128
Events:
AlexaTrigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 96c9d503-9cfe-4000-809f-2c8b8a3736d0
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 128
Events:
AlexaTrigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 2c1547a5-be00-41e2-aec5-5bbcccb28ce5
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 128
Transform: AWS::Serverless-2016-10-31
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Resources:
Effect: Allow
Resource: '*'
Version: '2012-10-17'
Runtime: nodejs10.x
Runtime: nodejs18.x
Type: AWS::Serverless::Function
CreateAuthChallengeInvocationPermission:
Properties:
Expand All @@ -59,7 +59,7 @@ Resources:
Bucket: <%REPO_BUCKET%>
Key: 2addf0d2-5ce9-4741-b1a7-34a25470bbfc
Handler: define-auth-challenge.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
Type: AWS::Serverless::Function
DefineAuthChallengeInvocationPermission:
Properties:
Expand All @@ -80,7 +80,7 @@ Resources:
Bucket: <%REPO_BUCKET%>
Key: cbbd73aa-965e-4170-8a3f-72670fc0f81d
Handler: pre-sign-up.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
Type: AWS::Serverless::Function
PreSignUpInvocationPermission:
Properties:
Expand Down Expand Up @@ -151,7 +151,7 @@ Resources:
Bucket: <%REPO_BUCKET%>
Key: 750580f0-e0a5-4250-9f57-70e8cbf49203
Handler: verify-auth-challenge-response.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
Type: AWS::Serverless::Function
VerifyAuthChallengeResponseInvocationPermission:
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: e52b633b-f6c5-481b-acbc-b0d94aac32cb
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 256
Transform: AWS::Serverless-2016-10-31
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 69e05eaf-b8f1-4a29-b379-0fb064226b03
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
OptionsApi:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 6353ff98-b2cd-44af-8ef5-c6e0383e464b
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
Api:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: fb1a3a5a-28d6-415a-85f4-0e358a30383f
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
SaveApi:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 18fa6025-1f7a-43b0-8715-37d55e17b71f
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
EmailApi:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 70d2c77a-a692-40b1-8c78-4eb25649afcf
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
Api:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: f5f8769e-fdae-4778-a078-828efebe97c1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 7e855ca1-e613-4e4f-b733-43ddd337b55b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: d4b73f19-7bd5-47a3-aa66-be568b0ea9e1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 5005d2f4-1627-41fd-9cef-bb27b804f7f7
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
SNS1:
Type: SNS
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke/templates/sar/dynamodb-display-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 664d7928-e50c-403a-9f59-d9bf93bc5c9b
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
GetApi:
Type: Api
Expand Down Expand Up @@ -163,4 +163,4 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 664d7928-e50c-403a-9f59-d9bf93bc5c9b
Runtime: nodejs10.x
Runtime: nodejs18.x
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/dynamodb-lex-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 2658129b-dbc7-49f1-97dd-f7a21ed3aa2f
Runtime: nodejs10.x
Runtime: nodejs18.x
Description: Log Lex intent to a DynamoDB table
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/hello-world-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: e492b2b5-8e5b-499e-9e60-6d6dbb9acd65
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/helloWorldLex-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Resources:
Bucket: <%REPO_BUCKET%>
Key: 1831d44b-8ccb-4610-b4f2-1ee88282bb42
Handler: lambda.handler
Runtime: nodejs10.x
Runtime: nodejs18.x
Description: A hello world application for a Lex based chatbot
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/https-request-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 92c64a18-abe6-4481-899b-6146fb8bec50
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 128
Transform: AWS::Serverless-2016-10-31
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: e1281f99-d6f1-4d54-8c31-947a673bf8d5
Runtime: nodejs10.x
Runtime: nodejs18.x
MemorySize: 512
Transform: AWS::Serverless-2016-10-31
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 9c739c4e-7e28-4b71-bd0d-d0270e7bc9bc
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
AuthorizerApiRoot:
Type: Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 54b95c42-b951-409a-aaab-1cf9576f207e
Runtime: nodejs10.x
Runtime: nodejs18.x
Events:
GetApi:
Type: Api
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/templates/sar/lambdium-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Resources:
CodeUri:
Bucket: <%REPO_BUCKET%>
Key: 9d35d21b-e9f4-4e59-8650-a2f9db304462
Runtime: nodejs10.x
Runtime: nodejs18.x
FunctionName: lambdium
Transform: AWS::Serverless-2016-10-31
Loading

0 comments on commit 957d8bb

Please sign in to comment.