moto/tests/test_ssm/test_ssm_cloudformation.py
Brian Pandola f4b81e69b8
Address pytest warnings (#3629)
* Address `boto` deprecation warnings

This commit eliminates the following warning:

../boto/ec2/connection.py:582:
  PendingDeprecationWarning: The current get_all_instances implementation will be replaced with get_all_reservations.

`boto` isn't likely to ever make good on this warning, but doing the replacement will
declutter the `moto` test output.

* Remove `invoke_lambda` tracebacks from unit test logging

If an exception is encountered, the details are returned in the response payload.
Printing the traceback was just adding noise to the pytest output.

* Use known AMIs in unit tests

This commit eliminates the following warning in the pytest output:

`PendingDeprecationWarning: Could not find AMI with image-id:ami-123456, in the near future this will cause an error.`

Known, pre-loaded AMI image ids are used instead of random ids that don't actually
exist in the moto backend.  The integrity of the tests is unaffected by this change.

A test has been added to provide explicit coverage of the PendingDeprecationWarning
raised when an invalid AMI image id is passed to moto.
2021-01-29 11:31:56 +00:00

72 lines
2.1 KiB
Python

import boto3
import json
from moto import mock_ssm, mock_cloudformation
from tests import EXAMPLE_AMI_ID
@mock_ssm
@mock_cloudformation
def test_get_command_invocations_from_stack():
stack_template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Test Stack",
"Resources": {
"EC2Instance1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": EXAMPLE_AMI_ID,
"KeyName": "test",
"InstanceType": "t2.micro",
"Tags": [
{"Key": "Test Description", "Value": "Test tag"},
{"Key": "Test Name", "Value": "Name tag for tests"},
],
},
}
},
"Outputs": {
"test": {
"Description": "Test Output",
"Value": "Test output value",
"Export": {"Name": "Test value to export"},
},
"PublicIP": {"Value": "Test public ip"},
},
}
cloudformation_client = boto3.client("cloudformation", region_name="us-east-1")
stack_template_str = json.dumps(stack_template)
response = cloudformation_client.create_stack(
StackName="test_stack",
TemplateBody=stack_template_str,
Capabilities=("CAPABILITY_IAM",),
)
client = boto3.client("ssm", region_name="us-east-1")
ssm_document = "AWS-RunShellScript"
params = {"commands": ["#!/bin/bash\necho 'hello world'"]}
response = client.send_command(
Targets=[
{"Key": "tag:aws:cloudformation:stack-name", "Values": ("test_stack",)}
],
DocumentName=ssm_document,
Parameters=params,
OutputS3Region="us-east-2",
OutputS3BucketName="the-bucket",
OutputS3KeyPrefix="pref",
)
cmd = response["Command"]
cmd_id = cmd["CommandId"]
instance_ids = cmd["InstanceIds"]
invocation_response = client.get_command_invocation(
CommandId=cmd_id, InstanceId=instance_ids[0], PluginName="aws:runShellScript"
)