code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def _get_definition_file(self) -> str:
"""
Returns
-------
str
JSON/YAML definition file path
Raises
------
MissingLocalDefinition
raised when resource property related to definition path is not specified.
"""
property_name... |
Returns
-------
str
JSON/YAML definition file path
Raises
------
MissingLocalDefinition
raised when resource property related to definition path is not specified.
| _get_definition_file | python | aws/aws-sam-cli | samcli/lib/utils/resource_trigger.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/resource_trigger.py | Apache-2.0 |
def get_path_handlers(self) -> List[PathHandler]:
"""
Returns
-------
List[PathHandler]
A single PathHandler for watching the definition file.
"""
file_path_handler = ResourceTrigger.get_single_file_path_handler(self.base_dir.joinpath(self._definition_file))
... |
Returns
-------
List[PathHandler]
A single PathHandler for watching the definition file.
| get_path_handlers | python | aws/aws-sam-cli | samcli/lib/utils/resource_trigger.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/resource_trigger.py | Apache-2.0 |
def _get_resource_type(self, resource_identifier: ResourceIdentifier) -> Optional[str]:
"""Get resource type of the resource
Parameters
----------
resource_identifier : ResourceIdentifier
Returns
-------
Optional[str]
Resource type of the resource
... | Get resource type of the resource
Parameters
----------
resource_identifier : ResourceIdentifier
Returns
-------
Optional[str]
Resource type of the resource
| _get_resource_type | python | aws/aws-sam-cli | samcli/lib/utils/resource_type_based_factory.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/resource_type_based_factory.py | Apache-2.0 |
def _get_generator_function(self, resource_identifier: ResourceIdentifier) -> Optional[Callable]:
"""Create an appropriate T object based on stack resource type
Parameters
----------
resource_identifier : ResourceIdentifier
Resource identifier of the resource
Return... | Create an appropriate T object based on stack resource type
Parameters
----------
resource_identifier : ResourceIdentifier
Resource identifier of the resource
Returns
-------
Optional[T]
Object T for the resource. Returns None if resource cannot ... | _get_generator_function | python | aws/aws-sam-cli | samcli/lib/utils/resource_type_based_factory.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/resource_type_based_factory.py | Apache-2.0 |
def retry(exc, attempts=3, delay=0.05, exc_raise=Exception, exc_raise_msg=""):
"""
Retry decorator which defaults to 3 attempts based on exponential backoff
and a delay of 50ms.
After retries are exhausted, a custom Exception and Error message are raised.
:param exc: Exception to be caught for retr... |
Retry decorator which defaults to 3 attempts based on exponential backoff
and a delay of 50ms.
After retries are exhausted, a custom Exception and Error message are raised.
:param exc: Exception to be caught for retry
:param attempts: number of attempts before exception is allowed to be raised.
... | retry | python | aws/aws-sam-cli | samcli/lib/utils/retry.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/retry.py | Apache-2.0 |
def _parse_s3_format_url(
url: Any,
bucket_name_property: str = "Bucket",
object_key_property: str = "Key",
version_property: Optional[str] = None,
) -> Dict:
"""
Method for parsing s3 urls that begin with s3://
e.g. s3://bucket/key
"""
parsed = urlparse(url)
query = parse_qs(par... |
Method for parsing s3 urls that begin with s3://
e.g. s3://bucket/key
| _parse_s3_format_url | python | aws/aws-sam-cli | samcli/lib/utils/s3.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/s3.py | Apache-2.0 |
def _parse_path_style_s3_url(
url: Any,
bucket_name_property: str = "Bucket",
object_key_property: str = "Key",
) -> Dict:
"""
Static method for parsing path style s3 urls.
e.g. https://s3.us-east-1.amazonaws.com/bucket/key
"""
parsed = urlparse(url)
result = dict()
# parsed.path... |
Static method for parsing path style s3 urls.
e.g. https://s3.us-east-1.amazonaws.com/bucket/key
| _parse_path_style_s3_url | python | aws/aws-sam-cli | samcli/lib/utils/s3.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/s3.py | Apache-2.0 |
def configure_logger(logger, formatter, level):
"""
Configure a Logger with the level provided and also the first handler's formatter.
If there is no handler in the logger, a new StreamHandler will be added.
Parameters
----------
logger logging.getLogger
Logg... |
Configure a Logger with the level provided and also the first handler's formatter.
If there is no handler in the logger, a new StreamHandler will be added.
Parameters
----------
logger logging.getLogger
Logger to configure
formatter logging.formatter
... | configure_logger | python | aws/aws-sam-cli | samcli/lib/utils/sam_logging.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/sam_logging.py | Apache-2.0 |
def __init__(self, stream: TextIO, stream_bytes: Optional[Union[TextIO, BytesIO]] = None, auto_flush: bool = False):
"""
Instatiates new StreamWriter to the specified stream
Parameters
----------
stream io.RawIOBase
Stream to wrap
stream_bytes io.TextIO | io.... |
Instatiates new StreamWriter to the specified stream
Parameters
----------
stream io.RawIOBase
Stream to wrap
stream_bytes io.TextIO | io.BytesIO
Stream to wrap if bytes are being written
auto_flush bool
Whether to autoflush the strea... | __init__ | python | aws/aws-sam-cli | samcli/lib/utils/stream_writer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/stream_writer.py | Apache-2.0 |
def write_bytes(self, output: bytes):
"""
Writes specified text to the underlying stream
Parameters
----------
output bytes-like object
Bytes to write into buffer
"""
# all these ifs are to satisfy the linting/type checking
if not self._stream_... |
Writes specified text to the underlying stream
Parameters
----------
output bytes-like object
Bytes to write into buffer
| write_bytes | python | aws/aws-sam-cli | samcli/lib/utils/stream_writer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/stream_writer.py | Apache-2.0 |
def write_str(self, output: str):
"""
Writes specified text to the underlying stream
Parameters
----------
output string object
String to write
"""
self._stream.write(output)
if self._auto_flush:
self._stream.flush() |
Writes specified text to the underlying stream
Parameters
----------
output string object
String to write
| write_str | python | aws/aws-sam-cli | samcli/lib/utils/stream_writer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/stream_writer.py | Apache-2.0 |
def default_loading_pattern(stream_writer: Optional[StreamWriter] = None, loading_pattern_rate: float = 0.5) -> None:
"""
A loading pattern that just prints '.' to the terminal
Parameters
----------
stream_writer: Optional[StreamWriter]
The stream to which to write the pattern
loading_p... |
A loading pattern that just prints '.' to the terminal
Parameters
----------
stream_writer: Optional[StreamWriter]
The stream to which to write the pattern
loading_pattern_rate: int
How frequently to generate the pattern
| default_loading_pattern | python | aws/aws-sam-cli | samcli/lib/utils/subprocess_utils.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/subprocess_utils.py | Apache-2.0 |
def invoke_subprocess_with_loading_pattern(
command_args: Dict[str, Any],
loading_pattern: Callable[[StreamWriter], None] = default_loading_pattern,
stream_writer: Optional[StreamWriter] = None,
is_running_terraform_command: Optional[bool] = None,
) -> Optional[Union[str, bytes]]:
"""
Wrapper fo... |
Wrapper for Popen to asynchronously invoke a subprocess while
printing a given pattern until the subprocess is complete.
If the log level is lower than INFO, stream the process stdout instead.
Parameters
----------
command_args: Dict[str, Any]
The arguments to give to the Popen call, s... | invoke_subprocess_with_loading_pattern | python | aws/aws-sam-cli | samcli/lib/utils/subprocess_utils.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/subprocess_utils.py | Apache-2.0 |
def gather_system_info() -> Dict[str, str]:
"""
Gather system info
Returns
-------
dict[str, str]
"""
from platform import platform, python_version
info = {
"python": python_version(),
"os": platform(),
}
return info |
Gather system info
Returns
-------
dict[str, str]
| gather_system_info | python | aws/aws-sam-cli | samcli/lib/utils/system_info.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/system_info.py | Apache-2.0 |
def gather_additional_dependencies_info() -> Dict[str, str]:
"""
Gather additional depedencies info
Returns
-------
dict[str, str]
A dictionary with the key representing the info we need
and value being the version number
"""
info = {
"docker_engine": _gather_docker_... |
Gather additional depedencies info
Returns
-------
dict[str, str]
A dictionary with the key representing the info we need
and value being the version number
| gather_additional_dependencies_info | python | aws/aws-sam-cli | samcli/lib/utils/system_info.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/system_info.py | Apache-2.0 |
def _gather_docker_info() -> str:
"""
Get Docker Engine version
Returns
-------
str
Version number of Docker Engine if available. Otherwise "Not available"
"""
import contextlib
import docker
from samcli.lib.constants import DOCKER_MIN_API_VERSION
from samcli.local.doc... |
Get Docker Engine version
Returns
-------
str
Version number of Docker Engine if available. Otherwise "Not available"
| _gather_docker_info | python | aws/aws-sam-cli | samcli/lib/utils/system_info.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/system_info.py | Apache-2.0 |
def _gather_cdk_info():
"""
Get AWS CDK version numbner.
AWS SAM CLI does not invoke CDK, but only uses the CFN templates generated from `cdk synth`.
Knowing the CDK version number will help us diagnose if any issue is caused by a new version of CDK.
Returns
-------
str
Version num... |
Get AWS CDK version numbner.
AWS SAM CLI does not invoke CDK, but only uses the CFN templates generated from `cdk synth`.
Knowing the CDK version number will help us diagnose if any issue is caused by a new version of CDK.
Returns
-------
str
Version number of AWS CDK if available, e.... | _gather_cdk_info | python | aws/aws-sam-cli | samcli/lib/utils/system_info.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/system_info.py | Apache-2.0 |
def _gather_terraform_info():
"""
Get Terraform version numbner.
AWS SAM CLI invokes Terraform for Terraform applications.
Knowing the Terraform version number will help us diagnose if any issue is caused by a new version of Terraform.
Returns
-------
str
Version number of Terrafor... |
Get Terraform version numbner.
AWS SAM CLI invokes Terraform for Terraform applications.
Knowing the Terraform version number will help us diagnose if any issue is caused by a new version of Terraform.
Returns
-------
str
Version number of Terraform if available, e.g. "1.2.1"
... | _gather_terraform_info | python | aws/aws-sam-cli | samcli/lib/utils/system_info.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/system_info.py | Apache-2.0 |
def create_tarball(
tar_paths: Dict[Union[str, Path], str],
tar_filter: Optional[Callable[[tarfile.TarInfo], Union[None, tarfile.TarInfo]]] = None,
mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"] = "w",
dereference: bool = False,
):
"""
Context Manger that creates the tarball of the Dock... |
Context Manger that creates the tarball of the Docker Context to use for building the image
Parameters
----------
tar_paths: Dict[Union[str, Path], str]
Key representing a full path to the file or directory and the Value representing the path within the tarball
tar_filter: Optional[Callabl... | create_tarball | python | aws/aws-sam-cli | samcli/lib/utils/tar.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/tar.py | Apache-2.0 |
def _validate_destinations_exists(tar_paths: Union[List[Union[str, Path]], List[Path]]) -> bool:
"""
Validates whether the destination of a symlink exists by resolving the link
and checking the resolved path.
Parameters
----------
tar_paths: List[Union[str, Path]]
A list of Paths to che... |
Validates whether the destination of a symlink exists by resolving the link
and checking the resolved path.
Parameters
----------
tar_paths: List[Union[str, Path]]
A list of Paths to check
Return
------
bool:
True all the checked paths exist, otherwise returns false
... | _validate_destinations_exists | python | aws/aws-sam-cli | samcli/lib/utils/tar.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/tar.py | Apache-2.0 |
def _is_within_directory(directory: Union[str, os.PathLike], target: Union[str, os.PathLike]) -> bool:
"""Checks if target is located under directory"""
abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)
prefix = os.path.commonprefix([abs_directory, abs_target])
return... | Checks if target is located under directory | _is_within_directory | python | aws/aws-sam-cli | samcli/lib/utils/tar.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/tar.py | Apache-2.0 |
def extract_tarfile(
tarfile_path: Union[str, os.PathLike] = "",
file_obj: Optional[IO[bytes]] = None,
unpack_dir: Union[str, os.PathLike] = "",
) -> None:
"""
Extracts a tarfile using the provided parameters. If file_obj is specified,
it is used instead of the file_obj opened for tarfile_path.
... |
Extracts a tarfile using the provided parameters. If file_obj is specified,
it is used instead of the file_obj opened for tarfile_path.
Parameters
----------
tarfile_path Union[str, os.PathLike]
Key representing a full path to the file or directory and the Value representing the path withi... | extract_tarfile | python | aws/aws-sam-cli | samcli/lib/utils/tar.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/tar.py | Apache-2.0 |
def to_timestamp(some_time):
"""
Converts the given datetime value to Unix timestamp
Parameters
----------
some_time : datetime.datetime
Value to be converted to unix epoch. This must be without any timezone identifier
Returns
-------
int
Unix timestamp of the given tim... |
Converts the given datetime value to Unix timestamp
Parameters
----------
some_time : datetime.datetime
Value to be converted to unix epoch. This must be without any timezone identifier
Returns
-------
int
Unix timestamp of the given time
| to_timestamp | python | aws/aws-sam-cli | samcli/lib/utils/time.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/time.py | Apache-2.0 |
def to_utc(some_time):
"""
Convert the given date to UTC, if the date contains a timezone.
Parameters
----------
some_time : datetime.datetime
datetime object to convert to UTC
Returns
-------
datetime.datetime
Converted datetime object
"""
# Convert timezone a... |
Convert the given date to UTC, if the date contains a timezone.
Parameters
----------
some_time : datetime.datetime
datetime object to convert to UTC
Returns
-------
datetime.datetime
Converted datetime object
| to_utc | python | aws/aws-sam-cli | samcli/lib/utils/time.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/time.py | Apache-2.0 |
def parse_date(date_string):
"""
Parse the given string as datetime object. This parser supports in almost any string formats.
For relative times, like `10min ago`, this parser computes the actual time relative to current UTC time. This
allows time to always be in UTC if an explicit time zone is not pr... |
Parse the given string as datetime object. This parser supports in almost any string formats.
For relative times, like `10min ago`, this parser computes the actual time relative to current UTC time. This
allows time to always be in UTC if an explicit time zone is not provided.
Parameters
--------... | parse_date | python | aws/aws-sam-cli | samcli/lib/utils/time.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/time.py | Apache-2.0 |
def check_newer_version(func):
"""
This function returns a wrapped function definition, which checks if there are newer version of SAM CLI available
Parameters
----------
func: function reference
Actual function (command) which will be executed
Returns
-------
function referenc... |
This function returns a wrapped function definition, which checks if there are newer version of SAM CLI available
Parameters
----------
func: function reference
Actual function (command) which will be executed
Returns
-------
function reference:
A wrapped function referenc... | check_newer_version | python | aws/aws-sam-cli | samcli/lib/utils/version_checker.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/version_checker.py | Apache-2.0 |
def _inform_newer_version(force_check=False) -> None:
"""
Compares installed SAM CLI version with the up to date version from PyPi,
and print information if up to date version is different then what is installed now
It will store last version check time into GlobalConfig, so that it won't be running al... |
Compares installed SAM CLI version with the up to date version from PyPi,
and print information if up to date version is different then what is installed now
It will store last version check time into GlobalConfig, so that it won't be running all the time
Currently, it will be checking weekly
Par... | _inform_newer_version | python | aws/aws-sam-cli | samcli/lib/utils/version_checker.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/version_checker.py | Apache-2.0 |
def fetch_and_compare_versions() -> None:
"""
Compare current up to date version with the installed one, and inform if a newer version available
"""
response = get(AWS_SAM_CLI_PYPI_ENDPOINT, timeout=PYPI_CALL_TIMEOUT_IN_SECONDS)
result = response.json()
latest_version = result.get("info", {}).ge... |
Compare current up to date version with the installed one, and inform if a newer version available
| fetch_and_compare_versions | python | aws/aws-sam-cli | samcli/lib/utils/version_checker.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/version_checker.py | Apache-2.0 |
def is_version_check_overdue(last_version_check) -> bool:
"""
Check if last version check have been made longer then a week ago
Parameters
----------
last_version_check: epoch time
last_version_check epoch time read from GlobalConfig
Returns
-------
bool:
True if last_v... |
Check if last version check have been made longer then a week ago
Parameters
----------
last_version_check: epoch time
last_version_check epoch time read from GlobalConfig
Returns
-------
bool:
True if last_version_check is None or older then a week, False otherwise
| is_version_check_overdue | python | aws/aws-sam-cli | samcli/lib/utils/version_checker.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/utils/version_checker.py | Apache-2.0 |
def _get_deployment_preferences_status(function):
"""
Takes a AWS::Serverless::Function resource and checks if resource have a deployment preferences applied
to it. If DeploymentPreference found then it returns its status if it is enabled or not.
"""
deployment_preference = function.get("Properties"... |
Takes a AWS::Serverless::Function resource and checks if resource have a deployment preferences applied
to it. If DeploymentPreference found then it returns its status if it is enabled or not.
| _get_deployment_preferences_status | python | aws/aws-sam-cli | samcli/lib/warnings/sam_cli_warning.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/warnings/sam_cli_warning.py | Apache-2.0 |
def check_template_for_warning(self, warning_name, template_dict):
"""
Checks provided template against the warning based on warning_name.
Parameters
----------
warning_name: Name of warning which needs to be checked.
template_dict: template dict
Returns
... |
Checks provided template against the warning based on warning_name.
Parameters
----------
warning_name: Name of warning which needs to be checked.
template_dict: template dict
Returns
-------
warning_message if warning detected. None if no warning found.... | check_template_for_warning | python | aws/aws-sam-cli | samcli/lib/warnings/sam_cli_warning.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/warnings/sam_cli_warning.py | Apache-2.0 |
def check(self, template_dict):
"""
Checking if template dictionary have CodeDeployWarning or not.
"""
functions = [
resource
for (_, resource) in template_dict.get("Resources", {}).items()
if resource.get("Type", "") == "AWS::Serverless::Function"
... |
Checking if template dictionary have CodeDeployWarning or not.
| check | python | aws/aws-sam-cli | samcli/lib/warnings/sam_cli_warning.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/warnings/sam_cli_warning.py | Apache-2.0 |
def check(self, template_dict):
"""
Checking if template dictionary have Function with Condition and DeploymentPreferences which
will trigger this warning.
"""
functions = [
resource
for (_, resource) in template_dict.get("Resources", {}).items()
... |
Checking if template dictionary have Function with Condition and DeploymentPreferences which
will trigger this warning.
| check | python | aws/aws-sam-cli | samcli/lib/warnings/sam_cli_warning.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/lib/warnings/sam_cli_warning.py | Apache-2.0 |
def construct_v1_event(
flask_request, port, binary_types, stage_name=None, stage_variables=None, operation_name=None, api_type=Route.API
) -> Dict[str, Any]:
"""
Helper method that constructs the Event to be passed to Lambda.
Used for Http apis with payload v1 and Rest apis because the payloads are alm... |
Helper method that constructs the Event to be passed to Lambda.
Used for Http apis with payload v1 and Rest apis because the payloads are almost identical
:param request flask_request: Flask Request
:param port: the port number
:param binary_types: list of binary types
:param stage_name: Optio... | construct_v1_event | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def construct_v2_event_http(
flask_request,
port,
binary_types,
stage_name=None,
stage_variables=None,
route_key=None,
request_time_epoch=int(time()),
request_time=datetime.utcnow().strftime("%d/%b/%Y:%H:%M:%S +0000"),
) -> Dict[str, Any]:
"""
Helper method that constructs the Ev... |
Helper method that constructs the Event 2.0 to be passed to Lambda
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
:param request flask_request: Flask Request
:param port: the port number
:param binary_types: list of binary types
:param s... | construct_v2_event_http | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def _query_string_params(flask_request):
"""
Constructs an APIGW equivalent query string dictionary
Parameters
----------
flask_request request
Request from Flask
Returns dict (str: str), dict (str: list of str)
-------
Empty dict if no query params where in the request oth... |
Constructs an APIGW equivalent query string dictionary
Parameters
----------
flask_request request
Request from Flask
Returns dict (str: str), dict (str: list of str)
-------
Empty dict if no query params where in the request otherwise returns a dictionary of key to value
... | _query_string_params | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def _query_string_params_v_2_0(flask_request):
"""
Constructs an APIGW equivalent query string dictionary using the 2.0 format
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#2.0
Parameters
----------
flask_request request
Request f... |
Constructs an APIGW equivalent query string dictionary using the 2.0 format
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#2.0
Parameters
----------
flask_request request
Request from Flask
Returns dict (str: str)
-------
... | _query_string_params_v_2_0 | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def _event_headers(flask_request, port):
"""
Constructs an APIGW equivalent headers dictionary
Parameters
----------
flask_request request
Request from Flask
int port
Forwarded Port
cors_headers dict
Dict of the Cors properties
Returns dict (str: str), dict (str... |
Constructs an APIGW equivalent headers dictionary
Parameters
----------
flask_request request
Request from Flask
int port
Forwarded Port
cors_headers dict
Dict of the Cors properties
Returns dict (str: str), dict (str: list of str)
-------
Returns a dic... | _event_headers | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def _event_http_cookies(flask_request):
"""
All cookie headers in the request are combined with commas.
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Parameters
----------
flask_request request
Request from Flask
Returns lis... |
All cookie headers in the request are combined with commas.
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Parameters
----------
flask_request request
Request from Flask
Returns list
-------
Returns a list of cookies... | _event_http_cookies | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def _event_http_headers(flask_request, port):
"""
Duplicate headers are combined with commas.
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Parameters
----------
flask_request request
Request from Flask
Returns list
----... |
Duplicate headers are combined with commas.
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Parameters
----------
flask_request request
Request from Flask
Returns list
-------
Returns a list of cookies
| _event_http_headers | python | aws/aws-sam-cli | samcli/local/apigw/event_constructor.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/event_constructor.py | Apache-2.0 |
def __init__(
self,
api: Api,
lambda_runner: LocalLambdaRunner,
static_dir: Optional[str] = None,
port: Optional[int] = None,
host: Optional[str] = None,
stderr: Optional[StreamWriter] = None,
ssl_context: Optional[Tuple[str, str]] = None,
):
"... |
Creates an ApiGatewayService
Parameters
----------
api : Api
an Api object that contains the list of routes and properties
lambda_runner : samcli.commands.local.lib.local_lambda.LocalLambdaRunner
The Lambda runner class capable of invoking the function
... | __init__ | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def create(self):
"""
Creates a Flask Application that can be started.
"""
# Setting sam local start-api to respond using HTTP/1.1 instead of the default HTTP/1.0
WSGIRequestHandler.protocol_version = "HTTP/1.1"
self._app = Flask(
__name__,
static... |
Creates a Flask Application that can be started.
| create | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _add_catch_all_path(self, methods: List[str], path: str, route: Route):
"""
Add the catch all route to the _app and the dictionary of routes.
:param list(str) methods: List of HTTP Methods
:param str path: Path off the base url
:param Route route: contains the default route ... |
Add the catch all route to the _app and the dictionary of routes.
:param list(str) methods: List of HTTP Methods
:param str path: Path off the base url
:param Route route: contains the default route configurations
| _add_catch_all_path | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _generate_route_keys(self, methods, path):
"""
Generates the key to the _dict_of_routes based on the list of methods
and path supplied
Parameters
----------
methods : List[str]
List of HTTP Methods
path : str
Path off the base url
... |
Generates the key to the _dict_of_routes based on the list of methods
and path supplied
Parameters
----------
methods : List[str]
List of HTTP Methods
path : str
Path off the base url
Yields
------
route_key : str
... | _generate_route_keys | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _construct_error_handling(self):
"""
Updates the Flask app with Error Handlers for different Error Codes
"""
# Both path and method not present
self._app.register_error_handler(404, ServiceErrorResponses.route_not_found)
# Path is present, but method not allowed
... |
Updates the Flask app with Error Handlers for different Error Codes
| _construct_error_handling | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _create_method_arn(self, flask_request: Request, event_type: str) -> str:
"""
Creates a method ARN with fake AWS values
Parameters
----------
flask_request: Request
Flask request object to get method and path
event_type: str
Type of event (API... |
Creates a method ARN with fake AWS values
Parameters
----------
flask_request: Request
Flask request object to get method and path
event_type: str
Type of event (API or HTTP)
Returns
-------
str
A built method ARN wit... | _create_method_arn | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _generate_lambda_token_authorizer_event(
self, flask_request: Request, route: Route, lambda_authorizer: LambdaAuthorizer
) -> dict:
"""
Creates a Lambda authorizer token event
Parameters
----------
flask_request: Request
Flask request object to get me... |
Creates a Lambda authorizer token event
Parameters
----------
flask_request: Request
Flask request object to get method and path
route: Route
Route object representing the endpoint to be invoked later
lambda_authorizer: LambdaAuthorizer
... | _generate_lambda_token_authorizer_event | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _generate_lambda_request_authorizer_event_http(
self, lambda_authorizer_payload: str, identity_values: list, method_arn: str
) -> dict:
"""
Helper method to generate part of the event required for different payload versions
for API Gateway V2
Parameters
---------... |
Helper method to generate part of the event required for different payload versions
for API Gateway V2
Parameters
----------
lambda_authorizer_payload: str
The payload version of the Lambda authorizer
identity_values: list
A list of string identi... | _generate_lambda_request_authorizer_event_http | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _generate_lambda_request_authorizer_event(
self, flask_request: Request, route: Route, lambda_authorizer: LambdaAuthorizer
) -> dict:
"""
Creates a Lambda authorizer request event
Parameters
----------
flask_request: Request
Flask request object to ge... |
Creates a Lambda authorizer request event
Parameters
----------
flask_request: Request
Flask request object to get method and path
route: Route
Route object representing the endpoint to be invoked later
lambda_authorizer: LambdaAuthorizer
... | _generate_lambda_request_authorizer_event | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _generate_lambda_authorizer_event(
self, flask_request: Request, route: Route, lambda_authorizer: LambdaAuthorizer
) -> dict:
"""
Generate a Lambda authorizer event
Parameters
----------
flask_request: Request
Flask request object to get method and en... |
Generate a Lambda authorizer event
Parameters
----------
flask_request: Request
Flask request object to get method and endpoint
route: Route
Route object representing the endpoint to be invoked later
lambda_authorizer: LambdaAuthorizer
... | _generate_lambda_authorizer_event | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _generate_lambda_event(self, flask_request: Request, route: Route, method: str, endpoint: str) -> dict:
"""
Helper function to generate the correct Lambda event
Parameters
----------
flask_request: Request
The global Flask Request object
route: Route
... |
Helper function to generate the correct Lambda event
Parameters
----------
flask_request: Request
The global Flask Request object
route: Route
The Route that was called
method: str
The method of the request (eg. GET, POST) from the Fl... | _generate_lambda_event | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _build_v1_context(self, route: Route) -> Dict[str, Any]:
"""
Helper function to a 1.0 request context
Parameters
----------
route: Route
The Route object that was invoked
Returns
-------
dict
JSON object containing context var... |
Helper function to a 1.0 request context
Parameters
----------
route: Route
The Route object that was invoked
Returns
-------
dict
JSON object containing context variables
| _build_v1_context | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _build_v2_context(self, route: Route) -> Dict[str, Any]:
"""
Helper function to a 2.0 request context
Parameters
----------
route: Route
The Route object that was invoked
Returns
-------
dict
JSON object containing context var... |
Helper function to a 2.0 request context
Parameters
----------
route: Route
The Route object that was invoked
Returns
-------
dict
JSON object containing context variables
| _build_v2_context | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _valid_identity_sources(self, request: Request, route: Route) -> bool:
"""
Validates if the route contains all the valid identity sources defined in the route's Lambda Authorizer
Parameters
----------
request: Request
Flask request object containing incoming requ... |
Validates if the route contains all the valid identity sources defined in the route's Lambda Authorizer
Parameters
----------
request: Request
Flask request object containing incoming request variables
route: Route
the Route object that contains the Lamb... | _valid_identity_sources | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _invoke_lambda_function(self, lambda_function_name: str, event: dict) -> Union[str, bytes]:
"""
Helper method to invoke a function and setup stdout+stderr
Parameters
----------
lambda_function_name: str
The name of the Lambda function to invoke
event: dic... |
Helper method to invoke a function and setup stdout+stderr
Parameters
----------
lambda_function_name: str
The name of the Lambda function to invoke
event: dict
The event object to pass into the Lambda function
Returns
-------
Un... | _invoke_lambda_function | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _request_handler(self, **kwargs):
"""
We handle all requests to the host:port. The general flow of handling a request is as follows
* Fetch request from the Flask Global state. This is where Flask places the request and is per thread so
multiple requests are still handled correctl... |
We handle all requests to the host:port. The general flow of handling a request is as follows
* Fetch request from the Flask Global state. This is where Flask places the request and is per thread so
multiple requests are still handled correctly
* Find the Lambda function to invoke by... | _request_handler | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _invoke_parse_lambda_authorizer(
self, lambda_authorizer: LambdaAuthorizer, auth_lambda_event: dict, route_lambda_event: dict, route: Route
) -> None:
"""
Helper method to invoke and parse the output of a Lambda authorizer
Parameters
----------
lambda_authorizer:... |
Helper method to invoke and parse the output of a Lambda authorizer
Parameters
----------
lambda_authorizer: LambdaAuthorizer
The route's Lambda authorizer
auth_lambda_event: dict
The event to pass to the Lambda authorizer
route_lambda_event: dic... | _invoke_parse_lambda_authorizer | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _get_current_route(self, flask_request):
"""
Get the route (Route) based on the current request
:param request flask_request: Flask Request
:return: Route matching the endpoint and method of the request
"""
method, endpoint = self.get_request_methods_endpoints(flask_... |
Get the route (Route) based on the current request
:param request flask_request: Flask Request
:return: Route matching the endpoint and method of the request
| _get_current_route | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def get_request_methods_endpoints(flask_request):
"""
Separated out for testing requests in request handler
:param request flask_request: Flask Request
:return: the request's endpoint and method
"""
endpoint = flask_request.endpoint
method = flask_request.method
... |
Separated out for testing requests in request handler
:param request flask_request: Flask Request
:return: the request's endpoint and method
| get_request_methods_endpoints | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _parse_v1_payload_format_lambda_output(lambda_output: str, binary_types, flask_request, event_type):
"""
Parses the output from the Lambda Container
:param str lambda_output: Output from Lambda Invoke
:param binary_types: list of binary types
:param flask_request: flash requ... |
Parses the output from the Lambda Container
:param str lambda_output: Output from Lambda Invoke
:param binary_types: list of binary types
:param flask_request: flash request object
:param event_type: determines the route event type
:return: Tuple(int, dict, str, bool)
... | _parse_v1_payload_format_lambda_output | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _parse_v2_payload_format_lambda_output(lambda_output: str, binary_types, flask_request):
"""
Parses the output from the Lambda Container. V2 Payload Format means that the event_type is only HTTP
:param str lambda_output: Output from Lambda Invoke
:param binary_types: list of binary ... |
Parses the output from the Lambda Container. V2 Payload Format means that the event_type is only HTTP
:param str lambda_output: Output from Lambda Invoke
:param binary_types: list of binary types
:param flask_request: flash request object
:return: Tuple(int, dict, str, bool)
... | _parse_v2_payload_format_lambda_output | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _should_base64_decode_body(binary_types, flask_request, lamba_response_headers, is_base_64_encoded):
"""
Whether or not the body should be decoded from Base64 to Binary
Parameters
----------
binary_types list(basestring)
Corresponds to self.binary_types (aka. wha... |
Whether or not the body should be decoded from Base64 to Binary
Parameters
----------
binary_types list(basestring)
Corresponds to self.binary_types (aka. what is parsed from SAM Template
flask_request flask.request
Flask request
lamba_response_h... | _should_base64_decode_body | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def _merge_response_headers(headers, multi_headers):
"""
Merge multiValueHeaders headers with headers
* If you specify values for both headers and multiValueHeaders, API Gateway merges them into a single list.
* If the same key-value pair is specified in both, the value will only appear... |
Merge multiValueHeaders headers with headers
* If you specify values for both headers and multiValueHeaders, API Gateway merges them into a single list.
* If the same key-value pair is specified in both, the value will only appear once.
Parameters
----------
headers di... | _merge_response_headers | python | aws/aws-sam-cli | samcli/local/apigw/local_apigw_service.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/local_apigw_service.py | Apache-2.0 |
def convert_path_to_flask(path):
"""
Converts a Path from an Api Gateway defined path to one that is accepted by Flask
Examples:
'/id/{id}' => '/id/<id>'
'/{proxy+}' => '/<path:proxy>'
:param str path: Path to convert to Flask defined path
:return str: Path rep... |
Converts a Path from an Api Gateway defined path to one that is accepted by Flask
Examples:
'/id/{id}' => '/id/<id>'
'/{proxy+}' => '/<path:proxy>'
:param str path: Path to convert to Flask defined path
:return str: Path representing a Flask path
| convert_path_to_flask | python | aws/aws-sam-cli | samcli/local/apigw/path_converter.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/path_converter.py | Apache-2.0 |
def convert_path_to_api_gateway(path):
"""
Converts a Path from a Flask defined path to one that is accepted by Api Gateway
Examples:
'/id/<id>' => '/id/{id}'
'/<path:proxy>' => '/{proxy+}'
:param str path: Path to convert to Api Gateway defined path
:return st... |
Converts a Path from a Flask defined path to one that is accepted by Api Gateway
Examples:
'/id/<id>' => '/id/{id}'
'/<path:proxy>' => '/{proxy+}'
:param str path: Path to convert to Api Gateway defined path
:return str: Path representing an Api Gateway path
| convert_path_to_api_gateway | python | aws/aws-sam-cli | samcli/local/apigw/path_converter.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/path_converter.py | Apache-2.0 |
def __init__(
self,
function_name: Optional[str],
path: str,
methods: List[str],
event_type: str = API,
payload_format_version: Optional[str] = None,
is_default_route: bool = False,
operation_name=None,
stack_path: str = "",
authorizer_name... |
Creates an ApiGatewayRoute
:param list(str) methods: http method
:param function_name: Name of the Lambda function this API is connected to
:param str path: Path off the base url
:param str event_type: Type of the event. "Api" or "HttpApi"
:param str payload_format_vers... | __init__ | python | aws/aws-sam-cli | samcli/local/apigw/route.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/route.py | Apache-2.0 |
def normalize_method(self, methods):
"""
Normalizes Http Methods. Api Gateway allows a Http Methods of ANY. This is a special verb to denote all
supported Http Methods on Api Gateway.
:param list methods: Http methods
:return list: Either the input http_method or one of the _ANY... |
Normalizes Http Methods. Api Gateway allows a Http Methods of ANY. This is a special verb to denote all
supported Http Methods on Api Gateway.
:param list methods: Http methods
:return list: Either the input http_method or one of the _ANY_HTTP_METHODS (normalized Http Methods)
| normalize_method | python | aws/aws-sam-cli | samcli/local/apigw/route.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/route.py | Apache-2.0 |
def lambda_authorizer_unauthorized() -> Response:
"""
Constructs a Flask response for when a route invokes a Lambda Authorizer, but
is the identity sources provided are not authorized for that method
Returns
-------
Response
A Flask Response object
""... |
Constructs a Flask response for when a route invokes a Lambda Authorizer, but
is the identity sources provided are not authorized for that method
Returns
-------
Response
A Flask Response object
| lambda_authorizer_unauthorized | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def missing_lambda_auth_identity_sources() -> Response:
"""
Constructs a Flask response for when a route contains a Lambda Authorizer
but is missing the required identity services
Returns
-------
Response
A Flask Response object
"""
response_d... |
Constructs a Flask response for when a route contains a Lambda Authorizer
but is missing the required identity services
Returns
-------
Response
A Flask Response object
| missing_lambda_auth_identity_sources | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def lambda_failure_response(*args):
"""
Helper function to create a Lambda Failure Response
:return: A Flask Response
"""
LOG.debug("Lambda execution failed %s", args)
response_data = jsonify(ServiceErrorResponses._LAMBDA_FAILURE)
return make_response(response_da... |
Helper function to create a Lambda Failure Response
:return: A Flask Response
| lambda_failure_response | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def lambda_body_failure_response(*args):
"""
Helper function to create a Lambda Body Failure Response
:return: A Flask Response
"""
response_data = jsonify(ServiceErrorResponses._LAMBDA_FAILURE)
return make_response(response_data, ServiceErrorResponses.HTTP_STATUS_CODE_5... |
Helper function to create a Lambda Body Failure Response
:return: A Flask Response
| lambda_body_failure_response | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def not_implemented_locally(message):
"""
Constructs a Flask Response for for when a Lambda function functionality is
not implemented
:return: a Flask Response
"""
exception_dict = {"message": message}
response_data = jsonify(exception_dict)
return make_r... |
Constructs a Flask Response for for when a Lambda function functionality is
not implemented
:return: a Flask Response
| not_implemented_locally | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def lambda_not_found_response(*args):
"""
Constructs a Flask Response for when a Lambda function is not found for an endpoint
:return: a Flask Response
"""
response_data = jsonify(ServiceErrorResponses._NO_LAMBDA_INTEGRATION)
return make_response(response_data, ServiceEr... |
Constructs a Flask Response for when a Lambda function is not found for an endpoint
:return: a Flask Response
| lambda_not_found_response | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def route_not_found(*args):
"""
Constructs a Flask Response for when a API Route (path+method) is not found. This is usually
HTTP 404 but with API Gateway this is a HTTP 403 (https://forums.aws.amazon.com/thread.jspa?threadID=2166840)
:return: a Flask Response
"""
respon... |
Constructs a Flask Response for when a API Route (path+method) is not found. This is usually
HTTP 404 but with API Gateway this is a HTTP 403 (https://forums.aws.amazon.com/thread.jspa?threadID=2166840)
:return: a Flask Response
| route_not_found | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def container_creation_failed(message):
"""
Constuct a Flask Response for when container creation fails for a Lambda Function
:return: a Flask Response
"""
response_data = jsonify({"message": message})
return make_response(response_data, ServiceErrorResponses.HTTP_STATUS_... |
Constuct a Flask Response for when container creation fails for a Lambda Function
:return: a Flask Response
| container_creation_failed | python | aws/aws-sam-cli | samcli/local/apigw/service_error_responses.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/service_error_responses.py | Apache-2.0 |
def find_identity_value(self, **kwargs) -> Any:
"""
Returns the identity value, if found
""" |
Returns the identity value, if found
| find_identity_value | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def find_identity_value(self, **kwargs) -> Optional[str]:
"""
Finds the header value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `headers`
Returns
-------
Optional[str]
... |
Finds the header value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `headers`
Returns
-------
Optional[str]
The string value of the header if it is found, otherwise None
... | find_identity_value | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def is_valid(self, **kwargs) -> bool:
"""
Validates whether the required header is present and matches the
validation expression, if defined.
Parameters
----------
kwargs: dict
Keyword arugments containing the incoming sources and validation expression
... |
Validates whether the required header is present and matches the
validation expression, if defined.
Parameters
----------
kwargs: dict
Keyword arugments containing the incoming sources and validation expression
Returns
-------
bool
... | is_valid | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def find_identity_value(self, **kwargs) -> Optional[str]:
"""
Finds the query string value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `querystring`
Returns
-------
Optional[str]
... |
Finds the query string value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `querystring`
Returns
-------
Optional[str]
The string value of the query parameter if one is found, ... | find_identity_value | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def find_identity_value(self, **kwargs) -> Optional[str]:
"""
Finds the context value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `context`
Returns
-------
Optional[str]
... |
Finds the context value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `context`
Returns
-------
Optional[str]
The string value of the context variable if it is found, otherwise... | find_identity_value | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def find_identity_value(self, **kwargs) -> Optional[str]:
"""
Finds the stage variable value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `stageVariables`
Returns
-------
Optional[... |
Finds the stage variable value that the identity source corresponds to
Parameters
----------
kwargs
Keyword arguments that should contain `stageVariables`
Returns
-------
Optional[str]
The stage variable if it is found, otherwise None
... | find_identity_value | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def __init__(
self,
authorizer_name: str,
type: str,
lambda_name: str,
identity_sources: List[str],
payload_version: str,
validation_string: Optional[str] = None,
use_simple_response: bool = False,
):
"""
Creates a Lambda Authorizer cla... |
Creates a Lambda Authorizer class
Parameters
----------
authorizer_name: str
The name of the Lambda Authorizer
type: str
The type of authorizer this is (token or request)
lambda_name: str
The name of the Lambda function this authorize... | __init__ | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def _parse_identity_sources(self, identity_sources: List[str]) -> None:
"""
Helper function to create identity source validation objects
Parameters
----------
identity_sources: List[str]
A list of identity sources to parse
"""
# validate incoming ide... |
Helper function to create identity source validation objects
Parameters
----------
identity_sources: List[str]
A list of identity sources to parse
| _parse_identity_sources | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def is_valid_response(self, response: Union[str, bytes], method_arn: str) -> bool:
"""
Validates whether a Lambda authorizer request is authenticated or not.
Parameters
----------
response: Union[str, bytes]
JSON string containing the output from a Lambda authorizer
... |
Validates whether a Lambda authorizer request is authenticated or not.
Parameters
----------
response: Union[str, bytes]
JSON string containing the output from a Lambda authorizer
method_arn: str
The method ARN of the route that invoked the Lambda author... | is_valid_response | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def _is_resource_authorized(self, response: dict, method_arn: str) -> bool:
"""
Validate if the current method ARN is actually authorized
Parameters
----------
response: dict
The response output from the Lambda authorizer (should be in IAM format)
method_arn:... |
Validate if the current method ARN is actually authorized
Parameters
----------
response: dict
The response output from the Lambda authorizer (should be in IAM format)
method_arn: str
The route's method ARN
Returns
-------
bool
... | _is_resource_authorized | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def _validate_simple_response(self, response: dict) -> bool:
"""
Helper method to validate if a Lambda authorizer response using simple responses is valid and authorized
Parameters
----------
response: dict
JSON object containing required simple response paramters
... |
Helper method to validate if a Lambda authorizer response using simple responses is valid and authorized
Parameters
----------
response: dict
JSON object containing required simple response paramters
Returns
-------
bool
True if the requ... | _validate_simple_response | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def get_context(self, response: Union[str, bytes]) -> Dict[str, Any]:
"""
Returns the context (if set) from the authorizer response and appends the principalId to it.
Parameters
----------
response: Union[str, bytes]
Output from Lambda authorizer
Returns
... |
Returns the context (if set) from the authorizer response and appends the principalId to it.
Parameters
----------
response: Union[str, bytes]
Output from Lambda authorizer
Returns
-------
Dict[str, Any]
The built authorizer context obje... | get_context | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def is_valid(self, response: dict) -> bool:
"""
Validates whether the property is present and of the correct type
Parameters
----------
response: dict
The response output from the Lambda authorizer (should be in IAM format)
Returns
-------
bo... |
Validates whether the property is present and of the correct type
Parameters
----------
response: dict
The response output from the Lambda authorizer (should be in IAM format)
Returns
-------
bool
True if present and of correct type
... | is_valid | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def validate_policy_document(auth_name: str, response: dict) -> None:
"""
Validate the properties of a Lambda authorizer response at the root level
Parameters
----------
auth_name: str
Name of the authorizer
response: dict
The response output from... |
Validate the properties of a Lambda authorizer response at the root level
Parameters
----------
auth_name: str
Name of the authorizer
response: dict
The response output from the Lambda authorizer (should be in IAM format)
| validate_policy_document | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def validate_statement(auth_name: str, response: dict) -> None:
"""
Validate the Statement(s) of a Lambda authorizer response's policy document
Parameters
----------
auth_name: str
Name of the authorizer
response: dict
The response output from the... |
Validate the Statement(s) of a Lambda authorizer response's policy document
Parameters
----------
auth_name: str
Name of the authorizer
response: dict
The response output from the Lambda authorizer (should be in IAM format)
| validate_statement | python | aws/aws-sam-cli | samcli/local/apigw/authorizers/lambda_authorizer.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/apigw/authorizers/lambda_authorizer.py | Apache-2.0 |
def is_custom_runtime(runtime):
"""
validated if a runtime is custom or not
Parameters
----------
runtime : str
runtime to be
Returns
-------
_type_
_description_
"""
if not runtime:
return False
provided_runtime = get_provided_runtime_from_custom_runt... |
validated if a runtime is custom or not
Parameters
----------
runtime : str
runtime to be
Returns
-------
_type_
_description_
| is_custom_runtime | python | aws/aws-sam-cli | samcli/local/common/runtime_template.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/common/runtime_template.py | Apache-2.0 |
def get_provided_runtime_from_custom_runtime(runtime):
"""
Gets the base lambda runtime for which a custom runtime is based on
Example:
rust (provided.al2) --> provided.al2
java11 --> None
Parameters
----------
runtime : str
Custom runtime or Lambda runtime
Returns
----... |
Gets the base lambda runtime for which a custom runtime is based on
Example:
rust (provided.al2) --> provided.al2
java11 --> None
Parameters
----------
runtime : str
Custom runtime or Lambda runtime
Returns
-------
str
returns the base lambda runtime for which ... | get_provided_runtime_from_custom_runtime | python | aws/aws-sam-cli | samcli/local/common/runtime_template.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/common/runtime_template.py | Apache-2.0 |
def create(self, context):
"""
Calls Docker API to creates the Docker container instance. Creating the container does *not* run the container.
Use ``start`` method to run the container
context: samcli.local.docker.container.ContainerContext
Context for the container manageme... |
Calls Docker API to creates the Docker container instance. Creating the container does *not* run the container.
Use ``start`` method to run the container
context: samcli.local.docker.container.ContainerContext
Context for the container management to run (build, invoke)
:re... | create | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def _create_mapped_symlink_files(self) -> Dict[str, Dict[str, str]]:
"""
Resolves top level symlinked files and folders that are found on the
host directory and creates additional bind mounts to correctly map them
inside of the container.
By default only `node_modules` are mounte... |
Resolves top level symlinked files and folders that are found on the
host directory and creates additional bind mounts to correctly map them
inside of the container.
By default only `node_modules` are mounted unless self.mount_symlinks is True
Returns
-------
Di... | _create_mapped_symlink_files | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def stop(self, timeout=3):
"""
Stop a container, with a given number of seconds between sending SIGTERM and SIGKILL.
Parameters
----------
timeout
Optional. Number of seconds between SIGTERM and SIGKILL. Effectively, the amount of time
the container has t... |
Stop a container, with a given number of seconds between sending SIGTERM and SIGKILL.
Parameters
----------
timeout
Optional. Number of seconds between SIGTERM and SIGKILL. Effectively, the amount of time
the container has to perform shutdown steps. Default: 3
... | stop | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def delete(self):
"""
Removes a container that was created earlier.
"""
if not self.is_created():
LOG.debug("Container was not created. Skipping deletion")
return
try:
self.docker_client.containers.get(self.id).remove(force=True) # Remove a c... |
Removes a container that was created earlier.
| delete | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def start(self, input_data=None):
"""
Calls Docker API to start the container. The container must be created at the first place to run.
It waits for the container to complete, fetches both stdout and stderr logs and returns through the
given streams.
Parameters
---------... |
Calls Docker API to start the container. The container must be created at the first place to run.
It waits for the container to complete, fetches both stdout and stderr logs and returns through the
given streams.
Parameters
----------
input_data
Optional. In... | start | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def _wait_for_socket_connection(self) -> None:
"""
Waits for a successful connection to the socket used to communicate with Docker.
"""
start_time = time.time()
while not self._can_connect_to_socket():
time.sleep(0.1)
current_time = time.time()
... |
Waits for a successful connection to the socket used to communicate with Docker.
| _wait_for_socket_connection | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def _can_connect_to_socket(self) -> bool:
"""
Checks if able to connect successully to the socket used to communicate with Docker.
"""
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
location = (self._container_host, self.rapid_port_host)
# connect_ex return... |
Checks if able to connect successully to the socket used to communicate with Docker.
| _can_connect_to_socket | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
def copy(self, from_container_path, to_host_path) -> None:
"""Copies a path from container into host path"""
if not self.is_created():
raise RuntimeError("Container does not exist. Cannot get logs for this container")
real_container = self.docker_client.containers.get(self.id)
... | Copies a path from container into host path | copy | python | aws/aws-sam-cli | samcli/local/docker/container.py | https://github.com/aws/aws-sam-cli/blob/master/samcli/local/docker/container.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.