How to use describe_activations method in localstack

Best Python code snippet using localstack_python

aws_ssm_activation.py

Source:aws_ssm_activation.py Github

copy

Full Screen

...116 module.exit_json(msg="SSM Activation Deleted", changed=True)117def get_ssm_activation(module, client, activation_id):118 try:119 if activation_id != 'None':120 ssm_output = client.describe_activations(121 Filters=[122 {123 'FilterKey': 'ActivationIds',124 'FilterValues': [activation_id]125 }126 ]127 )128 else:129 ssm_output = client.describe_activations()130 except is_boto3_error_code('InvalidInstanceId') as e:131 module.warn("Could not find activation.")132 except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:133 module.fail_json_aws(e, msg=e)134 module.exit_json(msg="SSM Activation List", output=ssm_output['ActivationList'])135def main():136 argument_spec = dict(137 iam_role=dict(type='str'),138 registration_limit=dict(type='int', default=1),139 state=dict(type='str', required=True, choices=['present', 'absent', 'create', 'delete', 'get'], aliases=['command']),140 activation_id=dict(type=str, default='None')141 )142 module = AnsibleAWSModule(143 argument_spec=argument_spec,...

Full Screen

Full Screen

ssm.py

Source:ssm.py Github

copy

Full Screen

1# Copyright 2016-2017 Capital One Services, LLC2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14from __future__ import absolute_import, division, print_function, unicode_literals15from c7n.exceptions import PolicyValidationError16from c7n.query import QueryResourceManager17from c7n.manager import resources18from c7n.utils import chunks, get_retry, local_session, type_schema19from c7n.actions import Action20from .aws import shape_validate21from .ec2 import EC222@resources.register('ssm-parameter')23class SSMParameter(QueryResourceManager):24 class resource_type(object):25 service = 'ssm'26 enum_spec = ('describe_parameters', 'Parameters', None)27 name = "Name"28 id = "Name"29 filter_name = None30 dimension = None31 universal_taggable = True32 type = "parameter"33 retry = staticmethod(get_retry(('Throttled',)))34 permissions = ('ssm:GetParameters',35 'ssm:DescribeParameters')36@resources.register('ssm-managed-instance')37class ManagedInstance(QueryResourceManager):38 class resource_type(object):39 service = 'ssm'40 enum_spec = ('describe_instance_information', 'InstanceInformationList', None)41 id = 'InstanceId'42 name = 'Name'43 date = 'RegistrationDate'44 dimension = None45 filter_name = None46 type = "managed-instance"47 permissions = ('ssm:DescribeInstanceInformation',)48@EC2.action_registry.register('send-command')49@ManagedInstance.action_registry.register('send-command')50class SendCommand(Action):51 """Run an SSM Automation Document on an instance.52 :Example:53 Find ubuntu 18.04 instances are active with ssm.54 .. code-block:: yaml55 policies:56 - name: ec2-osquery-install57 resource: ec258 filters:59 - type: ssm60 key: PingStatus61 value: Online62 - type: ssm63 key: PlatformName64 value: Ubuntu65 - type: ssm66 key: PlatformVersion67 value: 18.0468 actions:69 - type: send-command70 command:71 DocumentName: AWS-RunShellScript72 Parameters:73 commands:74 - wget https://pkg.osquery.io/deb/osquery_3.3.0_1.linux.amd64.deb75 - dpkg -i osquery_3.3.0_1.linux.amd64.deb76 """77 schema = type_schema(78 'send-command',79 command={'type': 'object'},80 required=('command',))81 permissions = ('ssm:SendCommand',)82 shape = "SendCommandRequest"83 annotation = 'c7n:SendCommand'84 def validate(self):85 shape_validate(self.data['command'], self.shape, 'ssm')86 # If used against an ec2 resource, require an ssm status filter87 # to ensure that we're not trying to send commands to instances88 # that aren't in ssm.89 if self.manager.type != 'ec2':90 return91 found = False92 for f in self.manager.iter_filters():93 if f.type == 'ssm':94 found = True95 break96 if not found:97 raise PolicyValidationError(98 "send-command requires use of ssm filter on ec2 resources")99 def process(self, resources):100 client = local_session(self.manager.session_factory).client('ssm')101 for resource_set in chunks(resources, 50):102 self.process_resource_set(client, resource_set)103 def process_resource_set(self, client, resources):104 command = dict(self.data['command'])105 command['InstanceIds'] = [106 r['InstanceId'] for r in resources]107 result = client.send_command(**command).get('Command')108 for r in resources:109 r.setdefault('c7n:SendCommand', []).append(result['CommandId'])110@resources.register('ssm-activation')111class SSMActivation(QueryResourceManager):112 class resource_type(object):113 service = 'ssm'114 enum_spec = ('describe_activations', 'ActivationList', None)115 id = 'ActivationId'116 name = 'Description'117 date = 'CreatedDate'118 dimension = None119 filter_name = None120 arn = False121 permissions = ('ssm:DescribeActivations',)122@SSMActivation.action_registry.register('delete')123class DeleteSSMActivation(Action):124 schema = type_schema('delete')125 permissions = ('ssm:DeleteActivation',)126 def process(self, resources):127 client = local_session(self.manager.session_factory).client('ssm')128 for a in resources:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful