def test(self): lbd_permission = awslambda.Permission("LbdPermission", Action="", FunctionName="", Principal="") lbd_func = awslambda.Function( "LbdFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") event_rule = events.Rule("EventRule") associate(lbd_permission, event_rule, lbd_func) assert lbd_permission.Action == "lambda:InvokeFunction" assert isinstance(lbd_permission.FunctionName, GetAtt) assert lbd_permission.Principal == "events.amazonaws.com" assert isinstance(lbd_permission.SourceArn, GetAtt) assert len(lbd_permission.DependsOn) == 2 assert len(event_rule.Targets) == 1 assert lbd_func.title in event_rule.Targets[0].Id
def test(self): lbd_permission = awslambda.Permission("LbdPermission", Action="", FunctionName="", Principal="") lbd_func = awslambda.Function( "LbdFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") api_method = apigateway.Method( "ApiMethod", Metadata={ TROPOSPHERE_METADATA_FIELD_NAME: { ResourceLevelField.ApiResource.FULL_PATH: "users" } }, AuthorizationType="none", HttpMethod="POST", ResourceId="", RestApiId="", ) associate(lbd_permission, api_method, lbd_func) assert lbd_permission.Action == "lambda:InvokeFunction" assert isinstance(lbd_permission.FunctionName, GetAtt) assert lbd_permission.Principal == "apigateway.amazonaws.com" assert isinstance(lbd_permission.SourceArn, Sub) assert len(lbd_permission.DependsOn) == 2
def test(self): event_src_map = awslambda.EventSourceMapping( title="MyEventSourceMapping", EventSourceArn="", FunctionName="", ) associate(lbd_func, dynamodb_table, event_src_map) assert isinstance(event_src_map.FunctionName, Ref) assert isinstance(event_src_map.EventSourceArn, GetAtt)
def test(self): ec2_inst = ec2.Instance("Ec2Instance", ) sg = ec2.SecurityGroup( "SecurityGroup", GroupDescription="", ) associate(ec2_inst, sg) assert isinstance(ec2_inst.SecurityGroupIds, list) assert isinstance(ec2_inst.SecurityGroupIds[0], Ref)
def test(self): ec2_inst = ec2.Instance("Ec2Instance", ) subnet = ec2.Subnet( "Subnet", CidrBlock="", VpcId="", ) associate(ec2_inst, subnet) assert isinstance(ec2_inst.SubnetId, Ref)
def test(self): sg = ec2.SecurityGroup( "SecurityGroup", GroupDescription="", ) vpc = ec2.VPC( "Vpc", CidrBlock="", ) associate(sg, vpc) assert isinstance(sg.VpcId, Ref)
def test(self): api_resource = apigateway.Resource( "ApiResource", ParentId="", PathPart="users", RestApiId="", ) associate(api_resource, rest_api, has_parent_resource=False) assert isinstance(api_resource.RestApiId, Ref) assert isinstance(api_resource.ParentId, GetAtt) assert api_resource.Metadata[mtdt.TROPOSPHERE_METADATA_FIELD_NAME][ mtdt.ResourceLevelField.ApiResource.FULL_PATH] == "users"
def test(self): lbd_func = awslambda.Function( title="MyFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") associate(lbd_func, kms_key) assert isinstance(lbd_func.KmsKeyArn, GetAtt)
def test(self): lbd_func = awslambda.Function( title="MyFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") assert isinstance(lbd_func.Role, str) associate(iam_role, lbd_func) # intentionally do it in reverse order assert isinstance(lbd_func.Role, Ref)
def test(self): api_method = apigateway.Method( "ApiMethod", AuthorizationType="none", HttpMethod="POST", ResourceId="", RestApiId="", Integration=apigateway.Integration(Type=""), ) api_authorizer = apigateway.Authorizer( "ApiAuthorizer", AuthorizerUri="", IdentitySource="", Name="", Type="", ) associate(api_method, api_authorizer) assert isinstance(api_method.AuthorizerId, Ref)
def test(self): lbd_permission = awslambda.Permission("LbdPermission", Action="", FunctionName="", Principal="") lbd_func = awslambda.Function( "LbdFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") authorizer = apigateway.Authorizer( "Authorizer", Name="MyAuthorizer", Type="", AuthorizerUri="", IdentitySource="", ) rest_api = apigateway.RestApi("RestApi", ) associate(rest_api, authorizer, lbd_func, lbd_permission, authorizer_type_is_token=True) assert lbd_permission.Action == "lambda:InvokeFunction" assert isinstance(lbd_permission.FunctionName, GetAtt) assert lbd_permission.Principal == "apigateway.amazonaws.com" assert isinstance(lbd_permission.SourceArn, Sub) assert len(lbd_permission.DependsOn) == 3 assert authorizer.Type == "TOKEN" assert authorizer.IdentitySource == "method.request.header.auth" assert isinstance(authorizer.RestApiId, Ref) assert isinstance(authorizer.AuthorizerUri, Sub) assert len(authorizer.DependsOn) == 2
def test(self): api_method = apigateway.Method( "ApiMethod", AuthorizationType="none", HttpMethod="POST", ResourceId="", RestApiId="", Integration=apigateway.Integration(Type=""), ) lbd_func = awslambda.Function( "LbdFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") associate(api_method, lbd_func) assert api_method.Integration.Type == "AWS" assert api_method.Integration.IntegrationHttpMethod == "POST" assert isinstance(api_method.Integration.Uri, Sub)
def test(self): api_method = apigateway.Method( "ApiMethod", AuthorizationType="none", HttpMethod="POST", ResourceId="", RestApiId="", ) api_resource = apigateway.Resource( "ApiResource", ParentId="", PathPart="users", RestApiId="", ) associate(api_method, api_resource) assert len( api_method.Metadata[mtdt.TROPOSPHERE_METADATA_FIELD_NAME]) == 0 associate(api_resource, rest_api, has_parent_resource=False) associate(api_method, api_resource) assert api_method.Metadata[mtdt.TROPOSPHERE_METADATA_FIELD_NAME][ mtdt.ResourceLevelField.ApiResource.FULL_PATH] == "users"
def test(self): api_resource1 = apigateway.Resource( "ApiResource1", ParentId="", PathPart="users", RestApiId="", ) api_resource2 = apigateway.Resource( "ApiResource2", ParentId="", PathPart="rest", RestApiId="", ) associate(api_resource1, api_resource2) assert isinstance(api_resource1.ParentId, Ref) assert len( api_resource1.Metadata[mtdt.TROPOSPHERE_METADATA_FIELD_NAME]) == 0 associate(api_resource2, rest_api, has_parent_resource=False) associate(api_resource1, api_resource2) assert api_resource1.Metadata[mtdt.TROPOSPHERE_METADATA_FIELD_NAME][ mtdt.ResourceLevelField.ApiResource.FULL_PATH] == "rest/users"
def test(self): # subnet first then sg lbd_func = awslambda.Function( title="MyFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") associate(lbd_func, public_subnet1) associate(lbd_func, public_subnet2) associate(lbd_func, sg) assert len(lbd_func.VpcConfig.SubnetIds) == 2 assert len(lbd_func.VpcConfig.SecurityGroupIds) == 1 # sg first then subnet lbd_func = awslambda.Function( title="MyFunc", Code=awslambda.Code( S3Bucket="my-bucket", S3Key="0.0.1.zip", ), Handler="my_func.handler", Role="arn:aws:iam::111122223333:role/todo", Runtime="python3.6") associate(lbd_func, sg) associate(lbd_func, public_subnet1) associate(lbd_func, public_subnet2) assert len(lbd_func.VpcConfig.SubnetIds) == 2 assert len(lbd_func.VpcConfig.SecurityGroupIds) == 1