Showing
4 changed files
with
68 additions
and
3 deletions
... | @@ -65,6 +65,24 @@ def invoke(ctx): | ... | @@ -65,6 +65,24 @@ def invoke(ctx): |
65 | 65 | ||
66 | @cli.command() | 66 | @cli.command() |
67 | @click.pass_context | 67 | @click.pass_context |
68 | +def dryrun(ctx): | ||
69 | + context = Context(ctx.obj['config'], ctx.obj['debug']) | ||
70 | + click.echo('invoking dryrun...') | ||
71 | + response = context.dryrun() | ||
72 | + click.echo(response) | ||
73 | + click.echo('...done') | ||
74 | + | ||
75 | +@cli.command() | ||
76 | +@click.pass_context | ||
77 | +def invoke_async(ctx): | ||
78 | + context = Context(ctx.obj['config'], ctx.obj['debug']) | ||
79 | + click.echo('invoking async...') | ||
80 | + response = context.invoke_async() | ||
81 | + click.echo(response) | ||
82 | + click.echo('...done') | ||
83 | + | ||
84 | +@cli.command() | ||
85 | +@click.pass_context | ||
68 | def tail(ctx): | 86 | def tail(ctx): |
69 | context = Context(ctx.obj['config'], ctx.obj['debug']) | 87 | context = Context(ctx.obj['config'], ctx.obj['debug']) |
70 | click.echo('tailing logs...') | 88 | click.echo('tailing logs...') |
... | @@ -124,6 +142,14 @@ def add_event_sources(ctx): | ... | @@ -124,6 +142,14 @@ def add_event_sources(ctx): |
124 | context.add_event_sources() | 142 | context.add_event_sources() |
125 | click.echo('...done') | 143 | click.echo('...done') |
126 | 144 | ||
145 | +@cli.command() | ||
146 | +@click.pass_context | ||
147 | +def update_event_sources(ctx): | ||
148 | + context = Context(ctx.obj['config'], ctx.obj['debug']) | ||
149 | + click.echo('updating event sources...') | ||
150 | + context.update_event_sources() | ||
151 | + click.echo('...done') | ||
152 | + | ||
127 | 153 | ||
128 | if __name__ == '__main__': | 154 | if __name__ == '__main__': |
129 | cli(obj={}) | 155 | cli(obj={}) | ... | ... |
... | @@ -122,6 +122,10 @@ class Context(object): | ... | @@ -122,6 +122,10 @@ class Context(object): |
122 | for event_source in self.event_sources: | 122 | for event_source in self.event_sources: |
123 | event_source.add(self.function) | 123 | event_source.add(self.function) |
124 | 124 | ||
125 | + def update_event_sources(self): | ||
126 | + for event_source in self.event_sources: | ||
127 | + event_source.update(self.function) | ||
128 | + | ||
125 | def create(self): | 129 | def create(self): |
126 | if self.policy: | 130 | if self.policy: |
127 | self.policy.create() | 131 | self.policy.create() |
... | @@ -140,6 +144,12 @@ class Context(object): | ... | @@ -140,6 +144,12 @@ class Context(object): |
140 | def invoke(self): | 144 | def invoke(self): |
141 | return self.function.invoke() | 145 | return self.function.invoke() |
142 | 146 | ||
147 | + def dryrun(self): | ||
148 | + return self.function.dryrun() | ||
149 | + | ||
150 | + def invoke_async(self): | ||
151 | + return self.function.invoke_async() | ||
152 | + | ||
143 | def tail(self): | 153 | def tail(self): |
144 | return self.function.tail() | 154 | return self.function.tail() |
145 | 155 | ... | ... |
... | @@ -38,6 +38,10 @@ class EventSource(object): | ... | @@ -38,6 +38,10 @@ class EventSource(object): |
38 | def batch_size(self): | 38 | def batch_size(self): |
39 | return self._config.get('batch_size', 100) | 39 | return self._config.get('batch_size', 100) |
40 | 40 | ||
41 | + @property | ||
42 | + def enabled(self): | ||
43 | + return self._config.get('enabled', True) | ||
44 | + | ||
41 | 45 | ||
42 | class KinesisEventSource(EventSource): | 46 | class KinesisEventSource(EventSource): |
43 | 47 | ||
... | @@ -62,10 +66,25 @@ class KinesisEventSource(EventSource): | ... | @@ -62,10 +66,25 @@ class KinesisEventSource(EventSource): |
62 | FunctionName=function.name, | 66 | FunctionName=function.name, |
63 | EventSourceArn=self.arn, | 67 | EventSourceArn=self.arn, |
64 | BatchSize=self.batch_size, | 68 | BatchSize=self.batch_size, |
65 | - StartingPosition=self.starting_position) | 69 | + StartingPosition=self.starting_position, |
70 | + Enabled=self.enabled | ||
71 | + ) | ||
72 | + LOG.debug(response) | ||
73 | + except Exception: | ||
74 | + LOG.exception('Unable to add event source') | ||
75 | + | ||
76 | + def update(self, function): | ||
77 | + response = None | ||
78 | + uuid = self._get_uuid(function) | ||
79 | + if uuid: | ||
80 | + try: | ||
81 | + response = self._lambda.update_event_source_mapping( | ||
82 | + BatchSize=self.batch_size, | ||
83 | + Enabled=self.enabled, | ||
84 | + FunctionName=function.arn) | ||
66 | LOG.debug(response) | 85 | LOG.debug(response) |
67 | except Exception: | 86 | except Exception: |
68 | - LOG.exception('Unable to add Kinesis event source') | 87 | + LOG.exception('Unable to update event source') |
69 | 88 | ||
70 | def remove(self, function): | 89 | def remove(self, function): |
71 | response = None | 90 | response = None | ... | ... |
... | @@ -207,14 +207,24 @@ class Function(object): | ... | @@ -207,14 +207,24 @@ class Function(object): |
207 | InvokeArgs=fp) | 207 | InvokeArgs=fp) |
208 | LOG.debug(response) | 208 | LOG.debug(response) |
209 | 209 | ||
210 | - def invoke(self, test_data=None): | 210 | + def _invoke(self, test_data, invocation_type): |
211 | if test_data is None: | 211 | if test_data is None: |
212 | test_data = self.test_data | 212 | test_data = self.test_data |
213 | LOG.debug('invoke %s', test_data) | 213 | LOG.debug('invoke %s', test_data) |
214 | with open(test_data) as fp: | 214 | with open(test_data) as fp: |
215 | response = self._lambda_svc.invoke( | 215 | response = self._lambda_svc.invoke( |
216 | FunctionName=self.name, | 216 | FunctionName=self.name, |
217 | + InvocationType=invocation_type, | ||
217 | LogType='Tail', | 218 | LogType='Tail', |
218 | Payload=fp.read()) | 219 | Payload=fp.read()) |
219 | LOG.debug(response) | 220 | LOG.debug(response) |
220 | return response | 221 | return response |
222 | + | ||
223 | + def invoke(self, test_data=None): | ||
224 | + return self._invoke(test_data, 'RequestResponse') | ||
225 | + | ||
226 | + def invoke_async(self, test_data=None): | ||
227 | + return self._invoke(test_data, 'Event') | ||
228 | + | ||
229 | + def dryrun(self, test_data=None): | ||
230 | + return self._invoke(test_data, 'DryRun') | ... | ... |
-
Please register or login to post a comment