diff --git a/README.md b/README.md index 6fb942aef..7a2862744 100644 --- a/README.md +++ b/README.md @@ -58,95 +58,95 @@ With the decorator wrapping the test, all the calls to s3 are automatically mock It gets even better! Moto isn't just for Python code and it isn't just for S3. Look at the [standalone server mode](https://github.com/spulec/moto#stand-alone-server-mode) for more information about running Moto with other languages. Here's the status of the other AWS services implemented: ```gherkin -|-------------------------------------------------------------------------------------| -| Service Name | Decorator | Development Status | -|-------------------------------------------------------------------------------------| -| ACM | @mock_acm | all endpoints done | -|-------------------------------------------------------------------------------------| -| API Gateway | @mock_apigateway | core endpoints done | -|-------------------------------------------------------------------------------------| -| Autoscaling | @mock_autoscaling | core endpoints done | -|-------------------------------------------------------------------------------------| -| Cloudformation | @mock_cloudformation | core endpoints done | -|-------------------------------------------------------------------------------------| -| Cloudwatch | @mock_cloudwatch | basic endpoints done | -|-------------------------------------------------------------------------------------| -| CloudwatchEvents | @mock_events | all endpoints done | -|-------------------------------------------------------------------------------------| -| Cognito Identity | @mock_cognitoidentity | basic endpoints done | -|-------------------------------------------------------------------------------------| -| Cognito Identity Provider | @mock_cognitoidp | basic endpoints done | -|-------------------------------------------------------------------------------------| -| Config | @mock_config | basic endpoints done | -| | | core endpoints done | -|-------------------------------------------------------------------------------------| -| Data Pipeline | @mock_datapipeline | basic endpoints done | -|-------------------------------------------------------------------------------------| -| DynamoDB | @mock_dynamodb | core endpoints done | -| DynamoDB2 | @mock_dynamodb2 | all endpoints + partial indexes | -|-------------------------------------------------------------------------------------| -| EC2 | @mock_ec2 | core endpoints done | -| - AMI | | core endpoints done | -| - EBS | | core endpoints done | -| - Instances | | all endpoints done | -| - Security Groups | | core endpoints done | -| - Tags | | all endpoints done | -|-------------------------------------------------------------------------------------| -| ECR | @mock_ecr | basic endpoints done | -|-------------------------------------------------------------------------------------| -| ECS | @mock_ecs | basic endpoints done | -|-------------------------------------------------------------------------------------| -| ELB | @mock_elb | core endpoints done | -|-------------------------------------------------------------------------------------| -| ELBv2 | @mock_elbv2 | all endpoints done | -|-------------------------------------------------------------------------------------| -| EMR | @mock_emr | core endpoints done | -|-------------------------------------------------------------------------------------| -| Glacier | @mock_glacier | core endpoints done | -|-------------------------------------------------------------------------------------| -| IAM | @mock_iam | core endpoints done | -|-------------------------------------------------------------------------------------| -| IoT | @mock_iot | core endpoints done | -| | @mock_iotdata | core endpoints done | -|-------------------------------------------------------------------------------------| -| Kinesis | @mock_kinesis | core endpoints done | -|-------------------------------------------------------------------------------------| -| KMS | @mock_kms | basic endpoints done | -|-------------------------------------------------------------------------------------| -| Lambda | @mock_lambda | basic endpoints done, requires | -| | | docker | -|-------------------------------------------------------------------------------------| -| Logs | @mock_logs | basic endpoints done | -|-------------------------------------------------------------------------------------| -| Organizations | @mock_organizations | some core endpoints done | -|-------------------------------------------------------------------------------------| -| Polly | @mock_polly | all endpoints done | -|-------------------------------------------------------------------------------------| -| RDS | @mock_rds | core endpoints done | -|-------------------------------------------------------------------------------------| -| RDS2 | @mock_rds2 | core endpoints done | -|-------------------------------------------------------------------------------------| -| Redshift | @mock_redshift | core endpoints done | -|-------------------------------------------------------------------------------------| -| Route53 | @mock_route53 | core endpoints done | -|-------------------------------------------------------------------------------------| -| S3 | @mock_s3 | core endpoints done | -|-------------------------------------------------------------------------------------| -| SecretsManager | @mock_secretsmanager | basic endpoints done | -|-------------------------------------------------------------------------------------| -| SES | @mock_ses | all endpoints done | -|-------------------------------------------------------------------------------------| -| SNS | @mock_sns | all endpoints done | -|-------------------------------------------------------------------------------------| -| SQS | @mock_sqs | core endpoints done | -|-------------------------------------------------------------------------------------| -| SSM | @mock_ssm | core endpoints done | -|-------------------------------------------------------------------------------------| -| STS | @mock_sts | core endpoints done | -|-------------------------------------------------------------------------------------| -| SWF | @mock_swf | basic endpoints done | -|-------------------------------------------------------------------------------------| -| X-Ray | @mock_xray | all endpoints done | +|-------------------------------------------------------------------------------------|-----------------------------| +| Service Name | Decorator | Development Status | Comment | +|-------------------------------------------------------------------------------------| | +| ACM | @mock_acm | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| API Gateway | @mock_apigateway | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Autoscaling | @mock_autoscaling | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Cloudformation | @mock_cloudformation | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Cloudwatch | @mock_cloudwatch | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| CloudwatchEvents | @mock_events | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| Cognito Identity | @mock_cognitoidentity | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| Cognito Identity Provider | @mock_cognitoidp | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| Config | @mock_config | basic endpoints done | | +| | | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Data Pipeline | @mock_datapipeline | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| DynamoDB | @mock_dynamodb | core endpoints done | API 20111205. Deprecated. | +| DynamoDB2 | @mock_dynamodb2 | all endpoints + partial indexes | API 20120810 (Latest) | +|-------------------------------------------------------------------------------------| | +| EC2 | @mock_ec2 | core endpoints done | | +| - AMI | | core endpoints done | | +| - EBS | | core endpoints done | | +| - Instances | | all endpoints done | | +| - Security Groups | | core endpoints done | | +| - Tags | | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| ECR | @mock_ecr | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| ECS | @mock_ecs | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| ELB | @mock_elb | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| ELBv2 | @mock_elbv2 | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| EMR | @mock_emr | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Glacier | @mock_glacier | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| IAM | @mock_iam | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| IoT | @mock_iot | core endpoints done | | +| | @mock_iotdata | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Kinesis | @mock_kinesis | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| KMS | @mock_kms | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| Lambda | @mock_lambda | basic endpoints done, requires | | +| | | docker | | +|-------------------------------------------------------------------------------------| | +| Logs | @mock_logs | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| Organizations | @mock_organizations | some core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Polly | @mock_polly | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| RDS | @mock_rds | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| RDS2 | @mock_rds2 | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Redshift | @mock_redshift | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| Route53 | @mock_route53 | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| S3 | @mock_s3 | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| SecretsManager | @mock_secretsmanager | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| SES | @mock_ses | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| SNS | @mock_sns | all endpoints done | | +|-------------------------------------------------------------------------------------| | +| SQS | @mock_sqs | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| SSM | @mock_ssm | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| STS | @mock_sts | core endpoints done | | +|-------------------------------------------------------------------------------------| | +| SWF | @mock_swf | basic endpoints done | | +|-------------------------------------------------------------------------------------| | +| X-Ray | @mock_xray | all endpoints done | | |-------------------------------------------------------------------------------------| ``` diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index cceedc86e..c4a085705 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -351,18 +351,21 @@ class CloudFormationResponse(BaseResponse): return template.render(exports=exports, next_token=next_token) def validate_template(self): - cfn_lint = self.cloudformation_backend.validate_template( - self._get_param("TemplateBody") - ) + template_body = self._get_param("TemplateBody") + template_url = self._get_param("TemplateURL") + if template_url: + template_body = self._get_stack_from_s3_url(template_url) + + cfn_lint = self.cloudformation_backend.validate_template(template_body) if cfn_lint: raise ValidationError(cfn_lint[0].message) description = "" try: - description = json.loads(self._get_param("TemplateBody"))["Description"] + description = json.loads(template_body)["Description"] except (ValueError, KeyError): pass try: - description = yaml.load(self._get_param("TemplateBody"))["Description"] + description = yaml.load(template_body)["Description"] except (yaml.ParserError, KeyError): pass template = self.response_template(VALIDATE_STACK_RESPONSE_TEMPLATE) diff --git a/moto/core/models.py b/moto/core/models.py index ba4564e4a..26ee1a1f5 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -10,6 +10,7 @@ import six import types from io import BytesIO from collections import defaultdict +from botocore.config import Config from botocore.handlers import BUILTIN_HANDLERS from botocore.awsrequest import AWSResponse from six.moves.urllib.parse import urlparse @@ -416,6 +417,13 @@ class ServerModeMockAWS(BaseMockAWS): import mock def fake_boto3_client(*args, **kwargs): + region = self._get_region(*args, **kwargs) + if region: + if "config" in kwargs: + kwargs["config"].__dict__["user_agent_extra"] += " region/" + region + else: + config = Config(user_agent_extra="region/" + region) + kwargs["config"] = config if "endpoint_url" not in kwargs: kwargs["endpoint_url"] = "http://localhost:5000" return real_boto3_client(*args, **kwargs) @@ -463,6 +471,14 @@ class ServerModeMockAWS(BaseMockAWS): if six.PY2: self._httplib_patcher.start() + def _get_region(self, *args, **kwargs): + if "region_name" in kwargs: + return kwargs["region_name"] + if type(args) == tuple and len(args) == 2: + service, region = args + return region + return None + def disable_patching(self): if self._client_patcher: self._client_patcher.stop() diff --git a/moto/core/responses.py b/moto/core/responses.py index c52e89898..676d7549d 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -188,6 +188,9 @@ class BaseResponse(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): default_region = "us-east-1" # to extract region, use [^.] region_regex = re.compile(r"\.(?P[a-z]{2}-[a-z]+-\d{1})\.amazonaws\.com") + region_from_useragent_regex = re.compile( + r"region/(?P[a-z]{2}-[a-z]+-\d{1})" + ) param_list_regex = re.compile(r"(.*)\.(\d+)\.") access_key_regex = re.compile( r"AWS.*(?P(?