3 months ago
    I have created a component resource that makes a call to
    in order to grab the current account id of the locally assumed aws role so it can be used to define an arn in a policy doc: (code snippet has been truncated to save space)
    import pulumi_aws as aws
    # gets account id
    current = aws.get_caller_identity()
    account_id = current.account_id
    # passes account id when defining policy
    self.lambda_policy = aws.iam.RolePolicy(
                    lambda physical_name: json.dumps(
                            "Version": "2012-10-17",
                            "Statement": [
                                    "Effect": "Allow",
                                    "Action": "logs:CreateLogGroup",
                                    "Resource": f"arn:aws:logs:us-east-1:{account_id}:*"
    When I instantiate this component resource in my project
    , it works as expected. However, when I run
    , I get the following error:
    ________________________________ ERROR collecting tests/ _________________________________
    tests/ in <module>
        test_args = ip_scan.MonitorAvailableIpsArgs(
    <string>:9: in __init__
    components/ in __post_init__
        account_id = aws.get_caller_identity().account_id
    .venv/lib/python3.10/site-packages/pulumi_aws/ in get_caller_identity
    E   AttributeError: 'NoneType' object has no attribute 'account_id'
    Any and all feedback is greatly appreciated!
    Ok I figured this one out. I had to mock the function call as follows:
    class MyMocks(pulumi.runtime.Mocks):
        def new_resource(self, args: pulumi.runtime.MockResourceArgs):
            return [ + "_id", args.inputs]
        def call(self, args: pulumi.runtime.MockCallArgs):
            if args.token == "aws:index/getCallerIdentity:getCallerIdentity":
                return {
                    "accountId": "123456789",
                    "arn": "myarn",
                    "id": "myid",
                    "userId": "achang3"
            return {}