Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 31 2019 22:19
    lightsgoout starred spulec/moto
  • Jan 31 2019 15:50
    drmorr0 commented #2030
  • Jan 31 2019 15:50
    drmorr0 commented #2032
  • Jan 31 2019 13:19
    Samir-Elsayed-Hub starred spulec/moto
  • Jan 31 2019 00:17
  • Jan 30 2019 18:19
    Brett55 commented #2035
  • Jan 30 2019 18:03
    dargueta commented #1886
  • Jan 30 2019 17:23
    dgea005 starred spulec/moto
  • Jan 30 2019 16:53
    sturmer opened #2040
  • Jan 30 2019 16:52
    perf123 commented #2038
  • Jan 30 2019 16:52
    perf123 closed #2038
  • Jan 30 2019 15:42
    jakul commented #1558
  • Jan 30 2019 15:40
    jakul commented #1558
  • Jan 30 2019 14:01
    perf123 edited #2038
  • Jan 30 2019 11:25
    craiga commented #2036
  • Jan 30 2019 07:26
    anshitmt edited #2039
  • Jan 30 2019 07:26
    anshitmt opened #2039
  • Jan 29 2019 22:50
    jayhale starred spulec/moto
  • Jan 29 2019 21:22
    mikegrima commented #1912
  • Jan 29 2019 21:19
    mikegrima commented #1886
hieptran1208
@hieptran1208
i updated to 4.1.0 but still have the same issue AttributeError: 'Client' object has no attribute 'api'
hieptran1208
@hieptran1208
Sorry its the other error: error running lambda AttributeError: 'str' object has no attribute 'get' happens at the invoke method
Émile Fugulin
@Sytten
Hi there! I was wondering if we could automate the process to release moto, I know how much of a pain it can be to be maintainer. So I feel like we could help the community a lot by automating the release process on new tags. I can code the github actions to do it, but there would still need to be some manual part to be done by @spulec to setup the secrets.
Matt Coleman
@mcoleman-sain
Hey Moto. Is anybody having a problem with Moto and Boto3 being incompatible right now? It seems like since Friday no combination of versions (including most recent) allow our tests to pass
Jack Danger
@JackDanger
@mcoleman-sain can you say more? We use both boto and boto3 in the test suite and run the tests against both Python 2 and 3, so in at least some cases it does work
You might find a different version of botocore allows your tests to pass?
@Sytten I believe the only reason we haven't automated the releasing process is a lack of time, not interest. If you wanted to add the GitHub Actions config to let us tag new releases, release pypi packages, and push new Docker images that would be fantastic
Steve Pulec
@spulec
Yes, would welcome help on getting the Github Actions setup. If someone call tell me what I need to configure, will be happy to make the change.
Émile Fugulin
@Sytten
I can do it, I just saw that there is already stuff for releases in travis. It looks like it might be broken? Do we want to keep everything in travis or move it to github actions?
Steve Pulec
@spulec
We automatically create prereleases on every commit. I would like that behavior to continue. If moving that to github actions makes it easier, I am cool with that. I don't think we care about anything else related to releases in the repo
Émile Fugulin
@Sytten
I made some progress on my fork: https://github.com/Sytten/moto/runs/288774196
Still some bugs, but build time is around 7m total (I love parallel builds).
I still need to figure out the server part.
Émile Fugulin
@Sytten
Releases should be easy, I am probably going to create another workflow for official releases on tag.
I am curious why you prefer not to create frequent small releases vs dev releases + large one every couple months
Steve Pulec
@spulec
Awesome!
I like for us to be able to merge in PRs and then users can install the new prerelease immediately.
By separating the permissions to merge PRs from those for creating releases, it also allows us to have many more people have PR merging permissions
Émile Fugulin
@Sytten
Make sense! I will continue to work on it this week and submit a PR. I will probably poke you to add the pypi secrets in github.
Steve Pulec
@spulec
Awesome. Thanks for all of the work!
John Corrales
@corrjo
I made a PR to add ec2-instance-connect support but noticed xray tests are failing, is anyone working on that? I can take a look, but don't want to duplicate work if someone else is already on it.
Émile Fugulin
@Sytten
Yeah I have the same problem for my PR, Mike Grima said he would look into it
Not sure if he made some progress
lexxish
@lexxish
Is there a reason to use localstack (https://localstack.cloud/) over just using moto directly?
Alex LordThorsen
@rawrgulmuffins

Hi everyone, I opened this issue a few days ago and I'm interested in writing a patch for it.

spulec/moto#2662

Would it be sufficient to copy this test but add dimensions and then do a retrieval?

https://github.com/spulec/moto/blob/master/tests/test_cloudwatch/test_cloudwatch_boto3.py#L143

Or are there other features of metric dimensions that would need to be added that aren't covered by my ticket?

John Corrales
@corrjo
Was wondering when we might expect a release? Releases seem a bit sporadic, would love a release schedule, or cd on master would be amazing.
Franz Allan Valencia See
@franz-see

how do i run moto server in debug mode?

I tried running this via my vscode

        {
            "name": "moto_server cognito-idp",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/moto/server.py",
            "console": "integratedTerminal",
            "args": [
                "cognito-idp"
            ],
            "justMyCode": false
        },

and then i tried hitting admin_initiate_auth. The server responds but my breakpoint does not stop in any of the admin_initiate_auth methods.

Any tips?

Franz Allan Valencia See
@franz-see
Looks like my breakpoints on admin_initiate_auth does not work because it loads moto inside the site-packages instead of in the source. To fix that, I added this in server.py after from __future__ import unicode_literalsand before moto is imported
import os, sys
additional_path = os.path.join(os.path.dirname(__file__), "..")
print('additional_path %s' % os.path.abspath(additional_path))
sys.path.append(additional_path)
Franz Allan Valencia See
@franz-see
Hi all, i filed two tickets and have fixes for both. hoping a maintainer can review them:
Franz Allan Valencia See
@franz-see
And this one as well spulec/moto#2672
Stijn Seghers
@Procrat
Hi all! We're looking at using moto at our company and we're pretty excited by it. We noticed that import moto takes ~3s (on my laptop) and it looks like all backends are being loaded at that point -- correct me if I'm wrong. Would you be interested in a PR that loads the backends only when they're being used?
Patrick Delaney
@ptdel
Hello, I have a fork with a WIP branch adding EFS to moto. Is it preferable to submit a PR for each implemented method with tests, or just the final addition of the service with all methods implemented.
John Corrales
@corrjo
@ptdel Not sure what the maintainers preference is, but for resource types i've added I made 1 PR with all methods and tests.
Patrick Delaney
@ptdel
thanks @corrjo I'll probably take that route, didn't want to surprise anybody with a large PR :-p
Ciaran Evans
@ciaranevans
Hi folks, I'm trying to write a helper function that checks for the completion of a list of Step Function executions. In my unit tests I would like a way to give a list of responses for describe_execution() to return. For example, if I call the method two times, I want them both to return with a status of RUNNING but the third and fourth calls return SUCCEEDED. Is there a way to do this with moto/mock?
Ciaran Evans
@ciaranevans
^ Cheated and just extracted that one method call into a wrapper.
Steve Pulec
@spulec
@ptdel feel free to submit all as one PR
Edwin Caldon
@edycop

Hi, I have a lambda function in a folder and it just put an item in DynamoDB:

import boto3
from botocore.exceptions import ClientError

REQUESTS_TABLE = os.getenv('REQUESTS_TABLE')

def handler(request: dict, _context) -> dict:
    item = request['body']
        response = save_data(item)

def save_data(item: dict, table) -> bool:
    row = {}
    row.update({'email': item['email']})
    row.update({'product_id': item['product_id']})
    print(f'item: {item}')
    try:
        dynamodb = boto3.resource("dynamodb")
        table = dynamodb.Table(REQUESTS_TABLE)
        table.put_item(TableName=REQUESTS_TABLE, Item=row)
    except ClientError as err:
        return False
    return True

But when I try to test it, this code is into other file and other folder:

import resources.requests.sfn_src.save_data as save_data
import unittest
import os

from moto import mock_dynamodb2
class SavedataTestMethods(unittest.TestCase):

    def setUp(self):
        print(f'setUp')

@mock_dynamodb2
    def test_handler_whithout_error(self):
        expected_event = {"statusCode": 200, "body": "ok"}
        input_event = {
            'code': 200,
            'body': {
                'email': 'test@mail.com',
                'product_id': '1',
            },
            'message': 'SUCCEEDED'
        }
        output_event = save_data.handler(input_event, {"table": self.table})

        self.assertEqual(expected_event, output_event)
        pass

if __name__ == "__main__":
    unittest.main()

I got this error:

An error occurred (ResourceNotFoundException) when calling the PutItem operation: Requested resource not found

But if in save_data function I printed "table" variable it shows the table that I need. So I don't know why it doesn't find the resource.

Edwin Caldon
@edycop

I figured out, in the same test function I must create the DynamoDB Table :

import resources.requests.sfn_src.save_data as save_data
import unittest
import os

from moto import mock_dynamodb2
import boto3

REQUESTS_TABLE = os.getenv('REQUESTS_TABLE')

class SavedataTestMethods(unittest.TestCase):

   @mock_dynamodb2
    def test_handler_whithout_error(self):
        dynamodb = boto3.resource("dynamodb")

        # Create the DynamoDB table.
        table = dynamodb.create_table(
            TableName=REQUESTS_TABLE,
            KeySchema=[
                {
                    'AttributeName': 'id',
                    'KeyType': 'HASH'
                }
            ],
            AttributeDefinitions=[
                {
                    'AttributeName': 'id',
                    'AttributeType': 'S'
                }
            ],
            ProvisionedThroughput={
                'ReadCapacityUnits': 5,
                'WriteCapacityUnits': 5
            }
        )

        table = dynamodb.Table(REQUESTS_TABLE)

        expected_event = {"statusCode": 200, "body": "ok"}
        input_event = {
            'code': 200,
            'body': {
                'email': 'test@mail.com',
                'product_id': '1',
                'url': 'https://url',
                'first_request': True
            },
            'message': 'SUCCEEDED'
        }

        output_event = save_data.handler(input_event, {})

        self.assertEqual(expected_event, output_event)

SOLVED :+1:

drewmullen
@drewmullen
does anyone have examples of how to use assert_called_with() against resources created by moto?
John Corrales
@corrjo
using assert_called_with() is just testing that you passed the right arguments to a function. you wouldn't necessarily use it to check created resources.
drewmullen
@drewmullen

so i decided this SPECIFIC test was not actually useful (scrapped it) so ignore the uselessness of the test. i guess my confusion is regarding fixtures in general. when i call client.attach_volume.assert_called_with() against my moto client fixture i get error: AttributeError: 'function' object has no attribute 'assert_called_with'

conftest.py

@pytest.fixture(scope='function')
def client(aws_credentials):
    with mock_ec2():
        yield boto3.client('ec2', region_name=REGION)

lambda_function.py

def attach_ebs_volume(client, instance_id, region):
    while utils.get_instance_state(client, instance_id) != "running":
        print("waiting for instance to start")
        time.sleep(5)
        #TODO: timeout

    for tag in utils.get_instance_tags(client, instance_id):
        if tag['Key'] == "volume":
            vol_tag = tag['Value']

    volume_id = utils.get_ebs_by_name_tag(client, vol_tag)
    client.attach_volume(
        Device="/dev/xvdz",
        InstanceId=instance_id,
        VolumeId=volume_id
    )

output from pytest:

    @mock.patch('utils.get_instance_state')
    @mock.patch('utils.get_instance_tags')
    def test_attach_ebs_volume(mock_get_instance_tags, mock_get_instance_state, client):
        volume_id = client.create_volume(Size=7, AvailabilityZone=REGION, TagSpecifications=VOLUME_TAGS)['VolumeId']
        instance_id = client.run_instances(ImageId='ami-123', MinCount=1, MaxCount=1, TagSpecifications=INSTANCE_TAGS)['Instances'][0]['InstanceId']

        mock_get_instance_state.return_value = 'running'
        mock_get_instance_tags.return_value = RETURN_TAGS

        r = lambda_function.attach_ebs_volume(client,
                                                instance_id=instance_id,
                                                region=REGION
                                                )

>       client.attach_volume.assert_called_with(Device="/dev/xvdz",
                                                InstanceId=instance_id,
                                                VolumeId=volume_id)
E       AttributeError: 'function' object has no attribute 'assert_called_with'

i was trying to test that client.attach_volume gets the right values. again, this is not actually that useful of a test but the functionality probably will in future tests

sunjiajing0815
@sunjiajing0815
Hi I am trying to mock lambda with moto, but keep getting this error when invoking a lambda: requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
Tomer Shalev
@tomers
Hi, is there an official Docker Hub release for moto?
Leo Shklovskii
@leos
Hi - what's the timeline for the next release? We'd love to see this fix released to clean up our CI logs: spulec/moto@882dfce
Asher Foa
@asherf
@leos moto automatically releases a version on every commit to master. it is a pre-release, but if you are blocked by a fix that was merged, you can always pin the pre-release in your requirements file.
When the team eventually releases a new version of moto, it will basically be turning whatever the latest pre-releases available to be a regular release.
Having said that, I think it is time to do a moto release ;-)
Leo Shklovskii
@leos
Thanks @asherf ! it's not a blocker and you're right we can definitely target a github commit but we feel way more warm and fuzzy when it's a tagged version - and yes we'd love to see the team do an actual moto release :-)
Marcus Guimaraes
@mzguimaraes
hey y'all, I need to mock an Organization that contains an account with a specific AWS ID, not the randomized value moto creates with orgs.create_account(). Are any of the following solutions feasible:
  1. call orgs.create_account(), then overwrite the ID of the account generated to match spec
  2. call orgs.create_account() in a way that forces the generated ID to be set to the spec ID
  3. mock an account join handshake procedure
    Thanks!
Niraj Bhatt
@nirajvbhatt
Any update on next release? Need organization tags usage. Thanks.
Niraj Bhatt
@nirajvbhatt

hey y'all, I need to mock an Organization that contains an account with a specific AWS ID, not the randomized value moto creates with orgs.create_account(). Are any of the following solutions feasible:

  1. call orgs.create_account(), then overwrite the ID of the account generated to match spec
  2. call orgs.create_account() in a way that forces the generated ID to be set to the spec ID
  3. mock an account join handshake procedure
    Thanks!

I think option 1 should work. I don't think option 2 is possible. No idea about option 3

Arcadiy Ivanov
@arcivanov
Hello folks