def test_create_sink_creates_LambdaSink(): # arrange env = LambdaEnvironment() # act result = env.get_sink() # assert assert isinstance(result, StdoutSink)
def test_get_type_returns_cfn_lambda_name(): # arrange env = LambdaEnvironment() # act result = env.get_type() # assert assert result == "AWS::Lambda::Function"
def test_get_log_group_name_returns_function_name(): # arrange expected_name = fake.word() os.environ["AWS_LAMBDA_FUNCTION_NAME"] = expected_name env = LambdaEnvironment() # act result = env.get_log_group_name() # assert assert result == expected_name
async def test_probe_returns_true_if_fcn_name_in_env(): # arrange os.environ["AWS_LAMBDA_FUNCTION_NAME"] = fake.word() env = LambdaEnvironment() # act result = await env.probe() # assert assert result is True
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import logging from aws_embedded_metrics import config from aws_embedded_metrics.environment import Environment from aws_embedded_metrics.environment.default_environment import DefaultEnvironment from aws_embedded_metrics.environment.lambda_environment import LambdaEnvironment from aws_embedded_metrics.environment.ec2_environment import EC2Environment from typing import Optional log = logging.getLogger(__name__) lambda_environment = LambdaEnvironment() ec2_environment = EC2Environment() default_environment = DefaultEnvironment() environments = [lambda_environment, ec2_environment] Config = config.get_config() class EnvironmentCache: environment: Optional[Environment] = None async def resolve_environment() -> Environment: if EnvironmentCache.environment is not None: log.debug("Environment resolved from cache.") return EnvironmentCache.environment
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import logging from aws_embedded_metrics.environment import Environment from aws_embedded_metrics.environment.default_environment import DefaultEnvironment from aws_embedded_metrics.environment.lambda_environment import LambdaEnvironment from aws_embedded_metrics.environment.ec2_environment import EC2Environment from typing import Optional log = logging.getLogger(__name__) environments = [LambdaEnvironment(), EC2Environment()] class EnvironmentCache: environment: Optional[Environment] = None async def resolve_environment() -> Environment: if EnvironmentCache.environment is not None: log.debug("Environment resolved from cache.") return EnvironmentCache.environment for env_under_test in environments: is_environment = False try: log.info("Testing environment: %s", env_under_test.__class__.__name__)