From 9d5de922aa5ffb131432f3f99fd88fc282ac0ce2 Mon Sep 17 00:00:00 2001 From: Saahil Dhulla Date: Fri, 10 Aug 2018 08:28:04 -0700 Subject: [PATCH] samcli generate-event changes added --- MANIFEST.in | 2 + requirements/base.txt | 2 + .../commands/local/generate_event/api/cli.py | 43 - samcli/commands/local/generate_event/cli.py | 38 +- .../local/generate_event/dynamodb/cli.py | 31 - .../local/generate_event/event_generation.py | 216 +++++ .../local/generate_event/kinesis/__init__.py | 0 .../local/generate_event/kinesis/cli.py | 48 -- .../local/generate_event/s3/__init__.py | 0 .../commands/local/generate_event/s3/cli.py | 39 - .../local/generate_event/schedule/__init__.py | 0 .../local/generate_event/schedule/cli.py | 31 - .../local/generate_event/sns/__init__.py | 0 .../commands/local/generate_event/sns/cli.py | 39 - samcli/commands/local/lib/events.py | 306 ------- .../generated_sample_events}/__init__.py | 0 .../event-mapping.json | 749 ++++++++++++++++++ .../lib/generated_sample_events/events.py | 130 +++ .../alexa-skills-kit/AlexaEndSession.json | 36 + .../alexa-skills-kit/AlexaIntentAnswer.json | 62 ++ .../AlexaIntentGetNewFact.json | 42 + .../AlexaIntentMyColorIs.json | 48 ++ .../alexa-skills-kit/AlexaIntentRecipe.json | 47 ++ .../alexa-skills-kit/AlexaStartSession.json | 38 + .../AlexaSmartHomeControlTurnOffRequest.json | 15 + .../AlexaSmartHomeControlTurnOnRequest.json | 15 + .../AlexaSmartHomeDiscoveryRequest.json | 11 + .../apigateway/ApiGatewayAuthorizer.json | 5 + .../events/apigateway/AwsProxy.json | 62 ++ .../events/batch/BatchGetJob.json | 6 + .../events/batch/BatchSubmitJob.json | 3 + .../cloudformation/CfnCreateRequest.json | 16 + .../events/cloudfront/CloudFrontABTest.json | 36 + .../CloudFrontAccessRequestInResponse.json | 42 + .../cloudfront/CloudFrontHttpRedirect.json | 30 + .../CloudFrontModifyQueryString.json | 37 + .../CloudFrontModifyResponseHeader.json | 35 + ...tMultipleRemoteCallsAggregateResponse.json | 30 + ...NormalizeQuerystringToImproveCacheHit.json | 37 + .../CloudFrontRedirectOnViewerCountry.json | 30 + ...loudFrontRedirectUnauthenticatedUsers.json | 24 + .../CloudFrontResponseGeneration.json | 24 + .../CloudFrontServeObjectOnViewerDevice.json | 48 ++ .../CloudFrontSimpleRemoteCall.json | 36 + .../events/codecommit/CodeCommit.json | 27 + .../events/codepipeline/CodePipeline.json | 45 ++ .../events/cognito/CognitoSyncTrigger.json | 20 + .../ConfigurationItemChangeNotification.json | 12 + ...edConfigurationItemChangeNotification.json | 12 + .../events/config/PeriodicRule.json | 12 + .../events/dynamodb/DynamoDBUpdate.json | 93 +++ .../events/events/ScheduledEvent.json | 12 + .../events/kinesis/Kinesis.json | 20 + .../events/kinesis/KinesisFirehose.json | 12 + .../kinesis/KinesisFirehoseApachelog.json | 11 + ...inesisFirehoseCloudwatchLogsProcessor.json | 27 + .../KinesisFirehoseStreamsAsSource.json | 19 + .../events/kinesis/KinesisFirehoseSyslog.json | 16 + .../events/lex/LexBookCar.json | 23 + .../events/lex/LexBookHotel.json | 22 + .../events/lex/LexMakeAppointment.json | 21 + .../events/lex/LexOrderFlowers.json | 21 + .../events/logs/CloudwatchLogs.json | 5 + .../rekognition/RekognitionS3Request.json | 38 + .../events/s3/S3Delete.json | 36 + .../events/s3/S3Put.json | 38 + .../events/ses/SesEmailReceiving.json | 97 +++ .../events/sns/Sns.json | 31 + .../events/sqs/Sqs.json | 20 + .../stepfunctions/StepFunctionsError.json | 1 + .../local/generate_event}/__init__.py | 0 .../local/generate_event/test_cli_integ.py | 19 + tests/unit/cli/test_main.py | 2 +- .../local/generate_event/api/__init__.py | 0 .../local/generate_event/api/test_cli.py | 23 - .../local/generate_event/dynamodb/__init__.py | 0 .../local/generate_event/dynamodb/test_cli.py | 20 - .../local/generate_event/kinesis/__init__.py | 0 .../local/generate_event/kinesis/test_cli.py | 25 - .../local/generate_event/s3/__init__.py | 0 .../local/generate_event/s3/test_cli.py | 22 - .../local/generate_event/schedule/__init__.py | 0 .../local/generate_event/schedule/test_cli.py | 20 - .../local/generate_event/sns/__init__.py | 0 .../local/generate_event/sns/test_cli.py | 22 - .../generate_event/test_event_generation.py | 157 ++++ tests/unit/commands/local/lib/test_events.py | 286 ------- 87 files changed, 2799 insertions(+), 977 deletions(-) delete mode 100644 samcli/commands/local/generate_event/api/cli.py delete mode 100644 samcli/commands/local/generate_event/dynamodb/cli.py create mode 100644 samcli/commands/local/generate_event/event_generation.py delete mode 100644 samcli/commands/local/generate_event/kinesis/__init__.py delete mode 100644 samcli/commands/local/generate_event/kinesis/cli.py delete mode 100644 samcli/commands/local/generate_event/s3/__init__.py delete mode 100644 samcli/commands/local/generate_event/s3/cli.py delete mode 100644 samcli/commands/local/generate_event/schedule/__init__.py delete mode 100644 samcli/commands/local/generate_event/schedule/cli.py delete mode 100644 samcli/commands/local/generate_event/sns/__init__.py delete mode 100644 samcli/commands/local/generate_event/sns/cli.py delete mode 100644 samcli/commands/local/lib/events.py rename samcli/commands/local/{generate_event/api => lib/generated_sample_events}/__init__.py (100%) create mode 100644 samcli/commands/local/lib/generated_sample_events/event-mapping.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events.py create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaEndSession.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentAnswer.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentGetNewFact.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentMyColorIs.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentRecipe.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaStartSession.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOffRequest.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOnRequest.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeDiscoveryRequest.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/apigateway/ApiGatewayAuthorizer.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/apigateway/AwsProxy.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/batch/BatchGetJob.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/batch/BatchSubmitJob.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudformation/CfnCreateRequest.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontABTest.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontAccessRequestInResponse.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontHttpRedirect.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyQueryString.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyResponseHeader.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontMultipleRemoteCallsAggregateResponse.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontNormalizeQuerystringToImproveCacheHit.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectOnViewerCountry.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectUnauthenticatedUsers.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontResponseGeneration.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontServeObjectOnViewerDevice.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontSimpleRemoteCall.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/codecommit/CodeCommit.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/codepipeline/CodePipeline.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/cognito/CognitoSyncTrigger.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/config/ConfigurationItemChangeNotification.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/config/OversizedConfigurationItemChangeNotification.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/config/PeriodicRule.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/dynamodb/DynamoDBUpdate.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/events/ScheduledEvent.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/kinesis/Kinesis.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehose.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseApachelog.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseCloudwatchLogsProcessor.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseStreamsAsSource.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseSyslog.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/lex/LexBookCar.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/lex/LexBookHotel.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/lex/LexMakeAppointment.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/lex/LexOrderFlowers.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/logs/CloudwatchLogs.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/rekognition/RekognitionS3Request.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/s3/S3Delete.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/s3/S3Put.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/ses/SesEmailReceiving.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/sns/Sns.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/sqs/Sqs.json create mode 100644 samcli/commands/local/lib/generated_sample_events/events/stepfunctions/StepFunctionsError.json rename {samcli/commands/local/generate_event/dynamodb => tests/integration/local/generate_event}/__init__.py (100%) create mode 100644 tests/integration/local/generate_event/test_cli_integ.py delete mode 100644 tests/unit/commands/local/generate_event/api/__init__.py delete mode 100644 tests/unit/commands/local/generate_event/api/test_cli.py delete mode 100644 tests/unit/commands/local/generate_event/dynamodb/__init__.py delete mode 100644 tests/unit/commands/local/generate_event/dynamodb/test_cli.py delete mode 100644 tests/unit/commands/local/generate_event/kinesis/__init__.py delete mode 100644 tests/unit/commands/local/generate_event/kinesis/test_cli.py delete mode 100644 tests/unit/commands/local/generate_event/s3/__init__.py delete mode 100644 tests/unit/commands/local/generate_event/s3/test_cli.py delete mode 100644 tests/unit/commands/local/generate_event/schedule/__init__.py delete mode 100644 tests/unit/commands/local/generate_event/schedule/test_cli.py delete mode 100644 tests/unit/commands/local/generate_event/sns/__init__.py delete mode 100644 tests/unit/commands/local/generate_event/sns/test_cli.py create mode 100644 tests/unit/commands/local/generate_event/test_event_generation.py delete mode 100644 tests/unit/commands/local/lib/test_events.py diff --git a/MANIFEST.in b/MANIFEST.in index beb7271dce..d7411b8c8e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,4 +3,6 @@ include requirements/base.txt include requirements/dev.txt recursive-include samcli/local/init/templates * recursive-include samcli/lib *.json +recursive-include samcli/commands/local/lib/generated_sample_events *.json prune tests + diff --git a/requirements/base.txt b/requirements/base.txt index 414b1f4e9e..87457929b9 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -10,3 +10,5 @@ docker>=3.3.0 dateparser~=0.7 python-dateutil~=2.6 pathlib2~=2.3.2; python_version<"3.4" +pystache~=0.5 + diff --git a/samcli/commands/local/generate_event/api/cli.py b/samcli/commands/local/generate_event/api/cli.py deleted file mode 100644 index 29d64ca7d8..0000000000 --- a/samcli/commands/local/generate_event/api/cli.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -Generates an Api Gateway Event for a Lambda Invoke -""" -import json - -import click - -from samcli.cli.main import pass_context, common_options as cli_framework_options -from samcli.commands.local.lib.events import generate_api_event - - -@click.command("api", short_help="Generates a sample Amazon API Gateway event") -@click.option("--method", "-m", - type=str, - default="POST", - help='HTTP method (default: "POST")') -@click.option("--body", "-b", - type=str, - default="{ \"test\": \"body\"}", - help='HTTP body (default: "{ \"test\": \"body\"}")') -@click.option("--resource", "-r", - type=str, - default="/{proxy+}", - help='API Gateway resource name (default: "/{proxy+}")') -@click.option("--path", "-p", - type=str, - default="/examplepath", - help=' HTTP path (default: "/examplepath")') -@cli_framework_options -@pass_context -def cli(ctx, method, body, resource, path): - # All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing - - do_cli(ctx, method, body, resource, path) # pragma: no cover - - -def do_cli(ctx, method, body, resource, path): - """ - Implementation of the ``cli`` method, just separated out for unit testing purposes - """ - event_dict = generate_api_event(method, body, resource, path) - event = json.dumps(event_dict, indent=4) - click.echo(event) diff --git a/samcli/commands/local/generate_event/cli.py b/samcli/commands/local/generate_event/cli.py index cd2c329bff..89f911a661 100644 --- a/samcli/commands/local/generate_event/cli.py +++ b/samcli/commands/local/generate_event/cli.py @@ -1,16 +1,11 @@ """ -Command group for "generate-event" suite for commands. +Sets up the cli for generate-event """ import click -from .s3.cli import cli as s3_cli -from .api.cli import cli as api_cli -from .dynamodb.cli import cli as dynamodb_cli -from .kinesis.cli import cli as kinesis_cli -from .schedule.cli import cli as schedule_cli -from .sns.cli import cli as sns_cli - +from samcli.cli.main import pass_context +from samcli.commands.local.generate_event.event_generation import GenerateEventCommand HELP_TEXT = """ You can use this command to generate sample payloads from different event sources @@ -18,22 +13,23 @@ event sources send to your Lambda functions.\n \b Generate the event that S3 sends to your Lambda function when a new object is uploaded -$ sam local generate-event s3 --bucket --key \n +$ sam local generate-event s3 [put/delete]\n +\b +You can even customize the event by adding parameter flags. To find which flags apply to your command, +run:\n +$ sam local generate-event s3 [put/delete] --help\n +Then you can add in those flags that you wish to customize using\n +$ sam local generate-event s3 [put/delete] --bucket --key \n \b After you generate a sample event, you can use it to test your Lambda function locally -$ sam local generate-event s3 --bucket --key | sam local invoke +$ sam local generate-event s3 [put/delete] --bucket --key | sam local invoke """ -@click.group("generate-event", help=HELP_TEXT) -def cli(): +@click.command(name="generate-event", cls=GenerateEventCommand, help=HELP_TEXT) +@pass_context +def cli(self): + """ + Generate an event for one of the services listed below: + """ pass # pragma: no cover - - -# Add individual commands under this group -cli.add_command(s3_cli) -cli.add_command(api_cli) -cli.add_command(dynamodb_cli) -cli.add_command(kinesis_cli) -cli.add_command(schedule_cli) -cli.add_command(sns_cli) diff --git a/samcli/commands/local/generate_event/dynamodb/cli.py b/samcli/commands/local/generate_event/dynamodb/cli.py deleted file mode 100644 index 6071b5f7e4..0000000000 --- a/samcli/commands/local/generate_event/dynamodb/cli.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Generates a DynamoDB Event for a Lambda Invoke -""" -import json - -import click - -from samcli.cli.main import pass_context, common_options as cli_framework_options -from samcli.commands.local.lib.events import generate_dynamodb_event - - -@click.command("dynamodb", short_help="Generates a sample Amazon DynamoDB event") -@click.option("--region", "-r", - type=str, - default="us-east-1", - help='The region the event should come from (default: "us-east-1")') -@pass_context -@cli_framework_options -def cli(ctx, region): - # All of the logic must be implemented in the ``do_cli`` method. This helps with easy unit testing - - do_cli(ctx, region) # pragma: no cover - - -def do_cli(ctx, region): - """ - Implementation of the ``cli`` method, just separated out for unit testing purposes - """ - event_dict = generate_dynamodb_event(region) - event = json.dumps(event_dict, indent=4) - click.echo(event) diff --git a/samcli/commands/local/generate_event/event_generation.py b/samcli/commands/local/generate_event/event_generation.py new file mode 100644 index 0000000000..6529498d29 --- /dev/null +++ b/samcli/commands/local/generate_event/event_generation.py @@ -0,0 +1,216 @@ +""" +Generates the services and commands for selection in SAM CLI generate-event +""" + +import functools +import click + +from samcli.cli.options import debug_option +import samcli.commands.local.lib.generated_sample_events.events as events + + +class ServiceCommand(click.MultiCommand): + """ + Top level command that defines the service provided + + Methods + ---------------- + get_command(self, ctx, cmd_name): + Get the subcommand(s) under a given service name. + list_commands(self, ctx): + List all of the subcommands + """ + + def __init__(self, events_lib, *args, **kwargs): + """ + Constructor for the ServiceCommand class + + Parameters + ---------- + events_lib: samcli.commands.local.lib.generated_sample_events.events + The events library that allows for CLI population and substitution + args: list + any arguments passed in before kwargs + kwargs: dict + dictionary containing the keys/values used to construct the ServiceCommand + """ + + super(ServiceCommand, self).__init__(*args, **kwargs) + if not events_lib: + raise ValueError("Events library is necessary to run this command") + + self.events_lib = events_lib + self.all_cmds = self.events_lib.event_mapping + + def get_command(self, ctx, cmd_name): + """ + gets the subcommands under the service name + + Parameters + ---------- + ctx : Context + the context object passed into the method + cmd_name : str + the service name + Returns + ------- + EventTypeSubCommand: + returns subcommand if successful, None if not. + """ + + if cmd_name not in self.all_cmds: + return None + return EventTypeSubCommand(self.events_lib, cmd_name, self.all_cmds[cmd_name]) + + def list_commands(self, ctx): + """ + lists the service commands available + + Parameters + ---------- + ctx: Context + the context object passed into the method + Returns + ------- + list + returns sorted list of the service commands available + """ + + return sorted(self.all_cmds.keys()) + + +class EventTypeSubCommand(click.MultiCommand): + """ + Class that describes the commands underneath a given service type + + Methods + ---------------- + get_command(self, ctx, cmd_name): + Get the subcommand(s) under a given service name. + list_commands(self, ctx): + List all of the subcommands + """ + + TAGS = 'tags' + + def __init__(self, events_lib, top_level_cmd_name, subcmd_definition, *args, **kwargs): + """ + constructor for the EventTypeSubCommand class + + Parameters + ---------- + events_lib: samcli.commands.local.lib.generated_sample_events.events + The events library that allows for CLI population and substitution + top_level_cmd_name: string + the service name + subcmd_definition: dict + the subcommands and their values underneath the service command + args: tuple + any arguments passed in before kwargs + kwargs: dict + key/value pairs passed into the constructor + """ + + super(EventTypeSubCommand, self).__init__(*args, **kwargs) + self.top_level_cmd_name = top_level_cmd_name + self.subcmd_definition = subcmd_definition + self.events_lib = events_lib + + def get_command(self, ctx, cmd_name): + + """ + gets the Click Commands underneath a service name + + Parameters + ---------- + ctx: Context + context object passed in + cmd_name: string + the service name + Returns + ------- + cmd: Click.Command + the Click Commands that can be called from the CLI + """ + + if cmd_name not in self.subcmd_definition: + return None + parameters = [] + for param_name in self.subcmd_definition[cmd_name][self.TAGS].keys(): + default = self.subcmd_definition[cmd_name][self.TAGS][param_name]["default"] + parameters.append(click.Option( + ["--{}".format(param_name)], + default=default, + help="Specify the {} name you'd like, otherwise the default = {}".format(param_name, default) + )) + + command_callback = functools.partial(self.cmd_implementation, + self.events_lib, + self.top_level_cmd_name, + cmd_name) + cmd = click.Command(name=cmd_name, + help=self.subcmd_definition[cmd_name]["help"], + params=parameters, + callback=command_callback) + + cmd = debug_option(cmd) + return cmd + + def list_commands(self, ctx): + """ + lists the commands underneath a particular event + + Parameters + ---------- + ctx: Context + the context object passed in + Returns + ------- + the sorted list of commands under a service + """ + return sorted(self.subcmd_definition.keys()) + + def cmd_implementation(self, events_lib, top_level_cmd_name, subcmd_name, *args, **kwargs): + """ + calls for value substitution in the event json and returns the + customized json as a string + + Parameters + ---------- + events_lib + top_level_cmd_name: string + the name of the service + subcmd_name: string + the name of the event under the service + args: tuple + any arguments passed in before kwargs + kwargs: dict + the keys and values for substitution in the json + Returns + ------- + event: string + returns the customized event json as a string + """ + event = events_lib.generate_event(top_level_cmd_name, subcmd_name, kwargs) + click.echo(event) + return event + + +class GenerateEventCommand(ServiceCommand): + """ + Class that brings ServiceCommand and EventTypeSubCommand into one for easy execution + """ + + def __init__(self, *args, **kwargs): + """ + Constructor for GenerateEventCommand class that brings together + ServiceCommand and EventTypeSubCommand into one class + + Parameters + ---------- + args: tuple + any arguments passed in before kwargs + kwargs: dict + commands, subcommands, and parameters for generate-event + """ + super(GenerateEventCommand, self).__init__(events.Events(), *args, **kwargs) diff --git a/samcli/commands/local/generate_event/kinesis/__init__.py b/samcli/commands/local/generate_event/kinesis/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samcli/commands/local/generate_event/kinesis/cli.py b/samcli/commands/local/generate_event/kinesis/cli.py deleted file mode 100644 index 2ade43e34d..0000000000 --- a/samcli/commands/local/generate_event/kinesis/cli.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Generates a Kinesis Event for a Lambda Invoke -""" -import base64 -import json - -import click - -from samcli.cli.main import pass_context, common_options as cli_framework_options -from samcli.commands.local.lib.events import generate_kinesis_event - - -@click.command("kinesis", short_help="Generates a sample Amazon Kinesis event") -@click.option("--region", "-r", - type=str, - default="us-east-1", - help='The region the event should come from (default: "us-east-1")') -@click.option("--partition", "-p", - type=str, - default="partitionKey-03", - help='The Kinesis partition key (default: "partitionKey-03")') -@click.option("--sequence", "-s", - type=str, - default="49545115243490985018280067714973144582180062593244200961", - help='The Kinesis sequence number (default: "49545115243490985018280067714973144582180062593244200961")') -@click.option("--data", "-d", - type=str, - default="Hello, this is a test 123.", - help='The Kinesis message payload. There is no need to base64 this - sam will do this for you ' - '(default: "Hello, this is a test 123.")') -@cli_framework_options -@pass_context -def cli(ctx, region, partition, sequence, data): - # All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing - - do_cli(ctx, region, partition, sequence, data) # pragma: no cover - - -def do_cli(ctx, region, partition, sequence, data): - """ - Implementation of the ``cli`` method, just separated out for unit testing purposes - """ - - # base64 encode the data - date_base64 = base64.urlsafe_b64encode(data.encode('utf8')) - event_dict = generate_kinesis_event(region, partition, sequence, date_base64) - event = json.dumps(event_dict, indent=4) - click.echo(event) diff --git a/samcli/commands/local/generate_event/s3/__init__.py b/samcli/commands/local/generate_event/s3/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samcli/commands/local/generate_event/s3/cli.py b/samcli/commands/local/generate_event/s3/cli.py deleted file mode 100644 index 89046f5109..0000000000 --- a/samcli/commands/local/generate_event/s3/cli.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -Generates a S3 Event for a Lambda Invoke -""" -import json - -import click - -from samcli.cli.main import pass_context, common_options as cli_framework_options -from samcli.commands.local.lib.events import generate_s3_event - - -@click.command("s3", short_help="Generates a sample Amazon S3 event") -@click.option("--region", "-r", - type=str, - default="us-east-1", - help='The region the event should come from (default: "us-east-1")') -@click.option("--bucket", "-b", - type=str, - default="example-bucket", - help='The S3 bucket the event should reference (default: "example-bucket")') -@click.option("--key", "-k", - type=str, - default="test/key", - help='The S3 key the event should reference (default: "test/key")') -@cli_framework_options -@pass_context -def cli(ctx, region, bucket, key): - # All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing - - do_cli(ctx, region, bucket, key) # pragma: no cover - - -def do_cli(ctx, region, bucket, key): - """ - Implementation of the ``cli`` method, just separated out for unit testing purposes - """ - event_dict = generate_s3_event(region, bucket, key) - event = json.dumps(event_dict, indent=4) - click.echo(event) diff --git a/samcli/commands/local/generate_event/schedule/__init__.py b/samcli/commands/local/generate_event/schedule/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samcli/commands/local/generate_event/schedule/cli.py b/samcli/commands/local/generate_event/schedule/cli.py deleted file mode 100644 index 107e7fad84..0000000000 --- a/samcli/commands/local/generate_event/schedule/cli.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Generates a Schedule Event for a Lambda Invoke -""" -import json - -import click - -from samcli.cli.main import pass_context, common_options as cli_framework_options -from samcli.commands.local.lib.events import generate_schedule_event - - -@click.command("schedule", short_help="Generates a sample scheduled event") -@click.option("--region", "-r", - type=str, - default="us-east-1", - help='The region the event should come from (default: "us-east-1")') -@cli_framework_options -@pass_context -def cli(ctx, region): - # All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing - - do_cli(ctx, region) # pragma: no cover - - -def do_cli(ctx, region): - """ - Implementation of the ``cli`` method, just separated out for unit testing purposes - """ - event_dict = generate_schedule_event(region) - event = json.dumps(event_dict, indent=4) - click.echo(event) diff --git a/samcli/commands/local/generate_event/sns/__init__.py b/samcli/commands/local/generate_event/sns/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samcli/commands/local/generate_event/sns/cli.py b/samcli/commands/local/generate_event/sns/cli.py deleted file mode 100644 index 9075a2e7a8..0000000000 --- a/samcli/commands/local/generate_event/sns/cli.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -Generates a SNS Event for a Lambda Invoke -""" -import json - -import click - -from samcli.cli.main import pass_context, common_options as cli_framework_options -from samcli.commands.local.lib.events import generate_sns_event - - -@click.command("sns", short_help="Generates a sample Amazon SNS event") -@click.option("--message", "-m", - type=str, - default="example message", - help='The SNS message body (default: "example message")') -@click.option("--topic", "-t", - type=str, - default="arn:aws:sns:us-east-1:111122223333:ExampleTopic", - help='The SNS topic (default: "arn:aws:sns:us-east-1:111122223333:ExampleTopic")') -@click.option("--subject", "-s", - type=str, - default="example subject", - help='The SNS subject (default: "example subject")') -@cli_framework_options -@pass_context -def cli(ctx, message, topic, subject): - # All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing - - do_cli(ctx, message, topic, subject) # pragma: no cover - - -def do_cli(ctx, message, topic, subject): - """ - Implementation of the ``cli`` method, just separated out for unit testing purposes - """ - event_dict = generate_sns_event(message, topic, subject) - event = json.dumps(event_dict, indent=4) - click.echo(event) diff --git a/samcli/commands/local/lib/events.py b/samcli/commands/local/lib/events.py deleted file mode 100644 index 428bcda18d..0000000000 --- a/samcli/commands/local/lib/events.py +++ /dev/null @@ -1,306 +0,0 @@ -""" -File that holds functions for generating different types of events -""" - -from samcli.local.events.api_event import ContextIdentity, ApiGatewayLambdaEvent, RequestContext - - -def generate_s3_event(region, bucket, key): - """ - Generates a S3 Event - - :param str region: AWS Region - :param str bucket: Name of the S3 bucket - :param str key: S3 Bucket Key - :return dict: Dictionary representing the S3 Event - """ - return { - "Records": [{ - "eventVersion": "2.0", - "eventTime": "1970-01-01T00:00:00.000Z", - "requestParameters": { - "sourceIPAddress": "127.0.0.1" - }, - "s3": { - "configurationId": "testConfigRule", - "object": { - "eTag": "0123456789abcdef0123456789abcdef", - "sequencer": "0A1B2C3D4E5F678901", - "key": key, - "size": 1024 - }, - "bucket": { - "arn": "arn:aws:s3:::{}".format(bucket), - "name": bucket, - "ownerIdentity": { - "principalId": "EXAMPLE" - } - }, - "s3SchemaVersion": "1.0" - }, - "responseElements": { - "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH", - "x-amz-request-id": "EXAMPLE123456789" - }, - "awsRegion": region, - "eventName": "ObjectCreated:Put", - "userIdentity": { - "principalId": "EXAMPLE" - }, - "eventSource": "aws:s3" - }] - } - - -def generate_sns_event(message, topic, subject): - """ - Generates a SNS Event - - :param str message: Message sent to the topic - :param str topic: Name of the Topic - :param str subject: Subject of the Topic - :return dict: Dictionary representing the SNS Event - """ - return { - "Records": [{ - "EventVersion": "1.0", - "EventSubscriptionArn": "arn:aws:sns:EXAMPLE", - "EventSource": "aws:sns", - "Sns": { - "SignatureVersion": "1", - "Timestamp": "1970-01-01T00:00:00.000Z", - "Signature": "EXAMPLE", - "SigningCertUrl": "EXAMPLE", - "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", - "Message": message, - "MessageAttributes": { - "Test": { - "Type": "String", - "Value": "TestString" - }, - "TestBinary": { - "Type": "Binary", - "Value": "TestBinary" - } - }, - "Type": "Notification", - "UnsubscribeUrl": "EXAMPLE", - "TopicArn": topic, - "Subject": subject - } - }] - } - - -def generate_schedule_event(region): - """ - Generates a Scheduled Event - - :param str region: AWS Region - :return dict: Dictionary representing the Schedule Event - """ - return { - "version": "0", - "account": "123456789012", - "region": region, - "detail": {}, - "detail-type": "Scheduled Event", - "source": "aws.events", - "time": "1970-01-01T00:00:00Z", - "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c", - "resources": [ - "arn:aws:events:us-east-1:123456789012:rule/my-schedule" - ] - } - - -def generate_dynamodb_event(region): - """ - Generates a DynamoDG Event - - :param str region: AWS region - :return dict: Dictionary representing the DynamoDB Event - """ - return { - "Records": [ - { - "eventID": "1", - "eventVersion": "1.0", - "dynamodb": { - "Keys": { - "Id": { - "N": "101" - } - }, - "NewImage": { - "Message": { - "S": "New item!" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES", - "SequenceNumber": "111", - "SizeBytes": 26 - }, - "awsRegion": region, - "eventName": "INSERT", - "eventSourceARN": "arn:aws:dynamodb:{}:account-id:table/" - "ExampleTableWithStream/stream/2015-06-27T00:48:05.899".format(region), - "eventSource": "aws:dynamodb" - }, - { - "eventID": "2", - "eventVersion": "1.0", - "dynamodb": { - "OldImage": { - "Message": { - "S": "New item!" - }, - "Id": { - "N": "101" - } - }, - "SequenceNumber": "222", - "Keys": { - "Id": { - "N": "101" - } - }, - "SizeBytes": 59, - "NewImage": { - "Message": { - "S": "This item has changed" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES" - }, - "awsRegion": region, - "eventName": "MODIFY", - "eventSourceARN": - "arn:aws:dynamodb:{}:account-id:table/" - "ExampleTableWithStream/stream/2015-06-27T00:48:05.899".format(region), - "eventSource": "aws:dynamodb" - }, - { - "eventID": "3", - "eventVersion": "1.0", - "dynamodb": { - "Keys": { - "Id": { - "N": "101" - } - }, - "SizeBytes": 38, - "SequenceNumber": "333", - "OldImage": { - "Message": { - "S": "This item has changed" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES" - }, - "awsRegion": region, - "eventName": "REMOVE", - "eventSourceARN": "arn:aws:dynamodb:{}:account-id:table/" - "ExampleTableWithStream/stream/2015-06-27T00:48:05.899".format(region), - "eventSource": "aws:dynamodb" - } - ] - } - - -def generate_kinesis_event(region, partition, sequence, data): - """ - Generates a Kinesis Event - - :param str region: AWS Region - :param str partition: PartitionKey in Kinesis - :param str sequence: Sequence Number as a string - :param str data: Data for the stream - :return dict: Dictionary representing the Kinesis Event - """ - return { - "Records": [{ - "eventID": "shardId-000000000000:{}".format(sequence), - "eventVersion": "1.0", - "kinesis": { - "approximateArrivalTimestamp": 1428537600, - "partitionKey": partition, - "data": data, - "kinesisSchemaVersion": "1.0", - "sequenceNumber": sequence - }, - "invokeIdentityArn": "arn:aws:iam::EXAMPLE", - "eventName": "aws:kinesis:record", - "eventSourceARN": "arn:aws:kinesis:EXAMPLE", - "eventSource": "aws:kinesis", - "awsRegion": region - }] - } - - -def generate_api_event(method, body, resource, path): - """ - Generates an Api Event - - :param str method: HTTP Method of the request - :param str body: Body of the request - :param str resource: Api Gateway resource path - :param str path: Request path - :return dict: Dictionary representing the Api Event - """ - headers = { - "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", - "Accept-Language": "en-US,en;q=0.8", - "CloudFront-Is-Desktop-Viewer": "true", - "CloudFront-Is-SmartTV-Viewer": "false", - "CloudFront-Is-Mobile-Viewer": "false", - "X-Forwarded-For": "127.0.0.1, 127.0.0.2", - "CloudFront-Viewer-Country": "US", - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", - "Upgrade-Insecure-Requests": "1", - "X-Forwarded-Port": "443", - "Host": "1234567890.execute-api.us-east-1.amazonaws.com", - "X-Forwarded-Proto": "https", - "X-Amz-Cf-Id": "aaaaaaaaaae3VYQb9jd-nvCd-de396Uhbp027Y2JvkCPNLmGJHqlaA==", - "CloudFront-Is-Tablet-Viewer": "false", - "Cache-Control": "max-age=0", - "User-Agent": "Custom User Agent String", - "CloudFront-Forwarded-Proto": "https", - "Accept-Encoding": "gzip, deflate, sdch" - } - - query_params = { - "foo": "bar" - } - - path_params = { - "proxy": path - } - - identity = ContextIdentity(source_ip='127.0.0.1') - - context = RequestContext(resource_path=resource, - http_method=method, - stage="prod", - identity=identity, - path=resource) - - event = ApiGatewayLambdaEvent(http_method=method, - body=body, - resource=resource, - request_context=context, - query_string_params=query_params, - headers=headers, - path_parameters=path_params, - path=path) - - return event.to_dict() diff --git a/samcli/commands/local/generate_event/api/__init__.py b/samcli/commands/local/lib/generated_sample_events/__init__.py similarity index 100% rename from samcli/commands/local/generate_event/api/__init__.py rename to samcli/commands/local/lib/generated_sample_events/__init__.py diff --git a/samcli/commands/local/lib/generated_sample_events/event-mapping.json b/samcli/commands/local/lib/generated_sample_events/event-mapping.json new file mode 100644 index 0000000000..1453a9f9bb --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/event-mapping.json @@ -0,0 +1,749 @@ +{ + "alexa-skills-kit": { + "end-session": { + "filename": "AlexaEndSession", + "help": "Generates an Amazon Alexa End Session Event", + "tags": { + "session-id": { + "default": "123456789012" + }, + "user-id": { + "default": "testUser" + }, + "application-id": { + "default": "987654321" + }, + "request-id": { + "default": "1234" + } + } + }, + "intent-answer": { + "filename": "AlexaIntentAnswer", + "help": "Generates an Amazon Alexa Intent Answer Event", + "tags": { + "session-id": { + "default": "123456789012" + }, + "user-id": { + "default": "testUser" + }, + "application-id": { + "default": "987654321" + }, + "request-id": { + "default": "1234" + } + } + }, + "intent-getnewfact": { + "filename": "AlexaIntentGetNewFact", + "help" : "Generates an Amazon Alexa Intent GetNewFact Event", + "tags": { + "session-id": { + "default": "123456789012" + }, + "user-id": { + "default": "testUser" + }, + "application-id": { + "default": "987654321" + }, + "request-id": { + "default": "1234" + } + } + }, + "intent-mycoloris" : { + "filename": "AlexaIntentMyColorIs", + "help" : "Generates an Amazon Alexa Intent MyColorIs Event", + "tags": { + "session-id": { + "default": "123456789012" + }, + "user-id": { + "default": "testUser" + }, + "application-id": { + "default": "987654321" + }, + "request-id": { + "default": "1234" + } + } + }, + "intent-recipe" : { + "filename": "AlexaIntentRecipe", + "help" : "Generates an Amazon Alexa Intent Recipe Event", + "tags": { + "session-id": { + "default": "123456789012" + }, + "user-id": { + "default": "testUser" + }, + "application-id": { + "default": "987654321" + }, + "request-id": { + "default": "1234" + } + } + }, + "start-session" : { + "filename": "AlexaStartSession", + "help" : "Generates an Amazon Alexa Start Session Event", + "tags": { + "session-id": { + "default": "123456789012" + }, + "user-id": { + "default": "testUser" + }, + "application-id": { + "default": "987654321" + }, + "request-id": { + "default": "1234" + } + } + } + }, + "alexa-smart-home" : { + "smart-home-control-turn-off-request": { + "filename": "AlexaSmartHomeControlTurnOffRequest", + "help" : "Generates an Amazon Alexa Smart Home Control Turn Off Request Event", + "tags": {} + }, + "smart-home-control-turn-on-request" : { + "filename": "AlexaSmartHomeControlTurnOnRequest", + "help" : "Generates an Amazon Alexa Smart Home Control Turn On Request Event", + "tags": {} + }, + "smart-home-discovery-request" : { + "filename": "AlexaSmartHomeDiscoveryRequest", + "help" : "Generates an Amazon Alexa Smart Home Discovery Request Event", + "tags": {} + } + }, + "apigateway": { + "authorizer" : { + "filename": "ApiGatewayAuthorizer", + "help" : "Generates an Amazon API Gateway Authorizer Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "region": { + "default": "us-east-1" + }, + "stage": { + "type": "string", + "default": "prod" + }, + "method": { + "type": "string", + "default": "POST" + }, + "resource": { + "type": "string", + "default": "{proxy+}" + }, + "restApiId": { + "type": "string", + "default": "example" + } + } + }, + "aws-proxy" : { + "filename": "AwsProxy", + "help" : "Generates an Amazon API Gateway AWS Proxy Event", + "tags": { + "body": { + "type": "string", + "default": "{\"test\":\"body\"}", + "encoding": "base64" + }, + "stage": { + "type": "string", + "default": "prod" + }, + "method": { + "type": "string", + "default": "POST" + }, + "resource": { + "type": "string", + "default": "/{proxy+}" + }, + "path": { + "type": "string", + "default": "path/to/resource" + }, + "account-id": { + "default": "123456789012" + } + } + } + }, + "batch": { + "get-job": { + "filename": "BatchGetJob", + "help" : "Generates an AWS Batch Get Job Event", + "tags": {} + }, + "submit-job" : { + "filename": "BatchSubmitJob", + "help" : "Generates an AWS Batch Submit Job Event", + "tags": {} + } + }, + "cloudformation": { + "create-request": { + "filename": "CfnCreateRequest", + "help" : "Generates an AWS CloudFormation Create Request Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "region": { + "default": "us-east-1" + }, + "stack": { + "type": "string", + "default": "MyStack" + } + } + } + }, + "cloudfront": { + "ab-test": { + "filename": "CloudFrontABTest", + "help" : "Generates an Amazon CloudFront A/B Test Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "access-request-in-response": { + "filename": "CloudFrontAccessRequestInResponse", + "help" : "Generates an Amazon CloudFront Access Request in Response Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "http-redirect": { + "filename": "CloudFrontHttpRedirect", + "help" : "Generates an Amazon CloudFront HTTP Redirect Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "modify-querystring" : { + "filename": "CloudFrontModifyQueryString", + "help" : "Generates an Amazon CloudFront Modify QueryString Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "modify-response-header": { + "filename": "CloudFrontModifyResponseHeader", + "help" : "Generates an Amazon CloudFront Modify Response Header Event", + "tags": {} + }, + "multiple-remote-calls-aggregate-response": { + "filename": "CloudFrontMultipleRemoteCallsAggregateResponse", + "help" : "Generates an Amazon CloudFront Multiple Remote Calls Aggregate Response Event", + "tags": { + "uri": { + "default": "/forecast/Seattle:NewYork:Chicago:SanFrancisco" + }, + "method": { + "default": "GET" + } + } + }, + "normalize-querystring-to-improve-cache-hit": { + "filename": "CloudFrontNormalizeQuerystringToImproveCacheHit", + "help" : "Generates an Amazon CloudFront Normalize Querystring Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "redirect-on-viewer-country": { + "filename": "CloudFrontRedirectOnViewerCountry", + "help" : "Generates an Amazon CloudFront Redirect on Viewer Country Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "redirect-unauthenticated-users": { + "filename": "CloudFrontRedirectUnauthenticatedUsers", + "help" : "Generates an Amazon CloudFront Redirect Unauthenticated Users Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "response-generation": { + "filename": "CloudFrontResponseGeneration", + "help" : "Generates an Amazon CloudFront Response Generation Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "serve-object-on-viewer-device": { + "filename": "CloudFrontServeObjectOnViewerDevice", + "help" : "Generates an Amazon CloudFront Serve Object on Viewer Device Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + }, + "simple-remote-call": { + "filename": "CloudFrontSimpleRemoteCall", + "help" : "Generates an Amazon CloudFront Simple Remote Call Event", + "tags": { + "uri": { + "default": "/test" + }, + "method": { + "default": "GET" + } + } + } + }, + "codecommit": { + "codecommit": { + "filename": "CodeCommit", + "help" : "Generates an AWS CodeCommit Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "region": { + "default": "us-east-1" + }, + "repository": { + "type": "string", + "default": "my-repo" + }, + "trigger": { + "type": "string", + "default": "my-trigger" + }, + "custom-data": { + "type": "string", + "default": "this is custom data" + } + } + } + }, + "codepipeline" : { + "job" : { + "filename": "CodePipeline", + "help": "Generates an AWS CodePipeline Job Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "input-bucket": { + "type": "string", + "default": "example-bucket" + }, + "input-key": { + "type": "string", + "default": "test/key" + }, + "output-bucket": { + "type": "string", + "default": "example-bucket2" + }, + "output-key": { + "type": "string", + "default": "test/key2" + } + } + } + }, + "cognito": { + "sync-trigger": { + "filename": "CognitoSyncTrigger", + "help" : "Generates an Amazon Cognito Sync Trigger Event", + "tags": { + "region": { + "default": "us-east-1" + } + } + } + }, + "config": { + "item-change-notification" : { + "filename": "ConfigurationItemChangeNotification", + "help" : "Generates an AWS Config Configuration Item Change Notification Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "account-id": { + "default": "123456789012" + } + } + }, + "oversized-item-change-notification": { + "filename": "OversizedConfigurationItemChangeNotification", + "help" : "Generates an AWS Config Oversized Configuration Item Change Notification Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "account-id": { + "default": "123456789012" + } + } + }, + "periodic-rule": { + "filename": "PeriodicRule", + "help" : "Generates an AWS Config Periodic Rule Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "account-id": { + "default": "123456789012" + } + } + } + }, + "dynamodb": { + "update": { + "filename": "DynamoDBUpdate", + "help" : "Generates an Amazon DynamoDB Update Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "region": { + "default": "us-east-1" + }, + "table": { + "type": "string", + "default": "ExampleTableWithStream" + } + } + } + }, + "events": { + "scheduled-event": { + "filename": "ScheduledEvent", + "help" : "Generates an Amazon CloudWatch Scheduled Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "region": { + "default": "us-east-1" + }, + "rule": { + "type": "string", + "default": "ExampleRule" + } + } + } + }, + "kinesis": { + "kinesis": { + "filename": "Kinesis", + "help" : "Generates an Amazon Kinesis Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "sequence": { + "type": "string", + "default": "49545115243490985018280067714973144582180062593244200961" + }, + "data": { + "type": "string", + "default": "Hello, this is a test 123.", + "encoding": "base64" + }, + "partition": { + "type": "string", + "default": "partitionKey-03" + } + } + }, + "kinesis-firehose": { + "filename": "KinesisFirehose", + "help" : "Generates an Amazon Kinesis Data Firehose Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "data": { + "default": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" + }, + "partition": { + "type": "string", + "default": "partitionKey-03" + } + } + }, + "apachelog": { + "filename": "KinesisFirehoseApachelog", + "help" : "Generates an Amazon Kinesis Data Firehose Apachelog Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "data": { + "default": "NjQuMjQyLjg4LjEwIC0gLSBbMDcvTWFyLzIwMDQ6MTY6MTA6MDIgLTA4MDBdICJHRVQgL21haWxtYW4vbGlzdGluZm8vaHNkaXZpc2lvbiBIVFRQLzEuMSIgMjAwIDYyOTE==" + } + } + }, + "cloudwatch-logs-processor": { + "filename": "KinesisFirehoseCloudwatchLogsProcessor", + "help" : "Generates an Amazon Kinesis Data Firehose Cloudwatch Logs Processor Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "account-id": { + "default": "123456789012" + } + } + }, + "streams-as-source" : { + "filename": "KinesisFirehoseStreamsAsSource", + "help" : "Generates an Amazon Kinesis Data Firehose Streams as Source Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "partition": { + "type": "string", + "default": "partitionKey-03" + }, + "data": { + "type": "string", + "default": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" + }, + "sequence": { + "type": "string", + "default": "49545115243490985018280067714973144582180062593244200961" + } + } + }, + "syslog": { + "filename": "KinesisFirehoseSyslog", + "help" : "Generates an Amazon Kinesis Data Firehose Syslog Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "data": { + "type": "string", + "default": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=" + } + } + } + }, + "lex": { + "book-car": { + "filename": "LexBookCar", + "help" : "Generates an Amazon Lex Book Car Event", + "tags": {} + }, + "book-hotel": { + "filename": "LexBookHotel", + "help" : "Generates an Amazon Lex Book Hotel Event", + "tags": {} + }, + "make-appointment": { + "filename": "LexMakeAppointment", + "help" : "Generates an Amazon Lex Make Appointment Event", + "tags": {} + }, + "order-flowers": { + "filename": "LexOrderFlowers", + "help" : "Generates an Amazon Lex Order Flowers Event", + "tags": {} + } + }, + "logs": { + "cloudwatch-logs": { + "filename": "CloudwatchLogs", + "help" : "Generates an Amazon Cloudwatch Logs Event", + "tags": {} + } + }, + "rekognition": { + "s3-request": { + "filename": "RekognitionS3Request", + "help" : "Generates an Amazon Rekognition S3 Request Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "bucket": { + "type": "string", + "default": "example-bucket" + }, + "key": { + "type": "string", + "default": "test/key", + "encoding": "url" + } + } + } + }, + "s3": { + "delete": { + "filename": "S3Delete", + "help" : "Generates an Amazon S3 Delete Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "bucket": { + "type": "string", + "default": "example-bucket" + }, + "key": { + "type": "string", + "default": "test/key", + "encoding": "url" + } + } + }, + "put": { + "filename": "S3Put", + "help" : "Generates an Amazon S3 Put Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "bucket": { + "type": "string", + "default": "example-bucket" + }, + "key": { + "type": "string", + "default": "test/key", + "encoding": "url" + } + } + } + }, + "ses": { + "email-receiving": { + "filename": "SesEmailReceiving", + "help" : "Generates an Amazon SES Email Receiving Event", + "tags": { + "region": { + "default": "us-east-1" + }, + "account-id": { + "default": "123456789012" + } + } + } + }, + "sns": { + "sns": { + "filename": "Sns", + "help" : "Generates an Amazon SNS Event", + "tags": { + "account-id": { + "default": "123456789012" + }, + "region": { + "default": "us-east-1" + }, + "topic": { + "type": "string", + "default": "ExampleTopic" + }, + "subject": { + "type": "string", + "default": "example subject" + }, + "message": { + "type": "string", + "default": "example message" + } + } + } + }, + "sqs": { + "sqs": { + "filename": "Sqs", + "help": "Generates an Amazon SQS Event", + "tags": { + "region": { + "type": "string", + "default": "us-east-1" + }, + "account-id": { + "default": "123456789012" + }, + "queue-name": { + "default": "MyQueue" + }, + "partition": { + "default": "partitionKey-03" + } + } + } + }, + "stepfunctions": { + "error": { + "filename": "StepFunctionsError", + "help" : "Generates an AWS StepFunctions Error Event", + "tags": {} + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events.py b/samcli/commands/local/lib/generated_sample_events/events.py new file mode 100644 index 0000000000..2046fc4698 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events.py @@ -0,0 +1,130 @@ +""" +Methods to expose the event types and generate the event jsons for use in SAM CLI generate-event +""" + +import os +import json +import base64 +from requests.utils import quote + +import pystache + + +class Events(object): + + """ + Events library class that loads and customizes event json files + + Methods + --------------- + expose_event_metadata(self): + return the event mapping file + generate-event(self, service_name, event_type, values_to_sub): + load in and substitute values into json file (if necessary) + """ + + def __init__(self): + """ + Constructor for event library + """ + + this_folder = os.path.dirname(os.path.abspath(__file__)) + file_name = os.path.join(this_folder, "event-mapping.json") + with open(file_name) as f: + self.event_mapping = json.load(f) + + def encode(self, tags, encoding, values_to_sub): + """ + reads the encoding type from the event-mapping.json + and determines whether a value needs encoding + + Parameters + ---------- + tags: dict + the values of a particular event that can be substituted + within the event json + encoding: string + string that helps navigate to the encoding field of the json + values_to_sub: dict + key/value pairs that will be substituted into the json + Returns + ------- + values_to_sub: dict + the encoded (if need be) values to substitute into the json. + """ + + for tag in tags: + if tags[tag].get(encoding) != "None": + if tags[tag].get(encoding) == "url": + values_to_sub[tag] = self.url_encode(values_to_sub[tag]) + if tags[tag].get(encoding) == "base64": + values_to_sub[tag] = self.base64_utf_encode(values_to_sub[tag]) + return values_to_sub + + def url_encode(self, value): + """ + url encodes the value passed in + + Parameters + ---------- + value: string + the value that needs to be encoded in the json + Returns + ------- + string: the url encoded value + """ + + return quote(value) + + def base64_utf_encode(self, value): + """ + base64 utf8 encodes the value passed in + + Parameters + ---------- + value: string + value that needs to be encoded in the json + Returns + ------- + string: the base64_utf encoded value + """ + + return base64.b64encode(value.encode('utf8')).decode('utf-8') + + def generate_event(self, service_name, event_type, values_to_sub): + """ + opens the event json, substitutes the values in, and + returns the customized event json + + Parameters + ---------- + service_name: string + name of the top level service (S3, apigateway, etc) + event_type: string + name of the event underneath the service + values_to_sub: dict + key/value pairs to substitute into the json + Returns + ------- + renderer.render(): string + string version of the custom event json + """ + + # set variables for easy calling + tags = self.event_mapping[service_name][event_type]['tags'] + values_to_sub = self.encode(tags, 'encoding', values_to_sub) + + # construct the path to the Events json file + this_folder = os.path.dirname(os.path.abspath(__file__)) + file_name = self.event_mapping[service_name][event_type]['filename'] + ".json" + file_path = os.path.join(this_folder, "events", service_name, file_name) + + # open the file + with open(file_path) as f: + data = json.load(f) + + data = json.dumps(data, indent=2) + + # return the substituted file + renderer = pystache.Renderer() + return renderer.render(data, values_to_sub) diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaEndSession.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaEndSession.json new file mode 100644 index 0000000000..a2ca73fd8c --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaEndSession.json @@ -0,0 +1,36 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.{{session_id}}", + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "attributes": {}, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + } + }, + "context": { + "System": { + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "SessionEndedRequest", + "requestId": "amzn1.echo-api.request.{{request_id}}", + "timestamp": "2016-10-27T21:11:41Z", + "locale": "en-US", + "reason": "USER_INITIATED" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentAnswer.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentAnswer.json new file mode 100644 index 0000000000..85aea4c50d --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentAnswer.json @@ -0,0 +1,62 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.{{session_id}}", + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "attributes": { + "score": 0, + "currentQuestionIndex": 0, + "speechOutput": "Question 1. What was Rudolph's father's name? 1. Blixen. 2. Comet. 3. Donner. 4. Dasher. ", + "correctAnswerText": "Donner", + "repromptText": "Question 1. What was Rudolph's father's name? 1. Blixen. 2. Comet. 3. Donner. 4. Dasher. ", + "questions": [ + 16, + 20, + 29, + 2, + 19 + ], + "STATE": "_TRIVIAMODE", + "correctAnswerIndex": 3 + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + } + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.{{request_id}}", + "timestamp": "2016-10-27T21:06:28Z", + "locale": "en-US", + "intent": { + "name": "AnswerIntent", + "slots": { + "Item": { + "name": "Answer", + "value": "1" + } + } + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentGetNewFact.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentGetNewFact.json new file mode 100644 index 0000000000..5d509306ef --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentGetNewFact.json @@ -0,0 +1,42 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.{{session_id}}", + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "attributes": {}, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + } + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.{{request_id}}", + "timestamp": "2016-10-27T21:06:28Z", + "locale": "en-US", + "intent": { + "name": "GetNewFactIntent", + "slots": {} + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentMyColorIs.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentMyColorIs.json new file mode 100644 index 0000000000..d2ab58905c --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentMyColorIs.json @@ -0,0 +1,48 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.{{session_id}}", + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "attributes": {}, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + + } + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.{{request_id}}", + "timestamp": "2016-10-27T21:06:28Z", + "locale": "en-US", + "intent": { + "name": "MyColorIsIntent", + "slots": { + "Color": { + "name": "Color", + "value": "blue" + } + } + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentRecipe.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentRecipe.json new file mode 100644 index 0000000000..db1c52baf6 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaIntentRecipe.json @@ -0,0 +1,47 @@ +{ + "version": "1.0", + "session": { + "new": false, + "sessionId": "amzn1.echo-api.session.{{session_id}}", + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "attributes": {}, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + } + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.userId" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.{{request_id}}", + "timestamp": "2016-10-27T21:06:28Z", + "locale": "en-US", + "intent": { + "name": "RecipeIntent", + "slots": { + "Item": { + "name": "Item", + "value": "snowball" + } + } + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaStartSession.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaStartSession.json new file mode 100644 index 0000000000..328781170e --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-skills-kit/AlexaStartSession.json @@ -0,0 +1,38 @@ +{ + "version": "1.0", + "session": { + "new": true, + "sessionId": "amzn1.echo-api.session.{{session_id}}", + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + }, + "attributes": {} + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.{{application_id}}" + }, + "user": { + "userId": "amzn1.ask.account.{{user_id}}" + }, + "device": { + "supportedInterfaces": { + "AudioPlayer": {} + } + } + } + }, + "request": { + "type": "LaunchRequest", + "requestId": "amzn1.echo-api.request.{{request_id}}", + "timestamp": "2016-10-27T18:21:44Z", + "locale": "en-US" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOffRequest.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOffRequest.json new file mode 100644 index 0000000000..0dc25663d6 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOffRequest.json @@ -0,0 +1,15 @@ +{ + "header": { + "messageId": "E2D17F2F-EBD0-4B1F-BB1E-8CEE81ADCBBC", + "name": "TurnOffRequest", + "namespace": "Alexa.ConnectedHome.Control", + "payloadVersion": "2" + }, + "payload": { + "accessToken": "1", + "appliance": { + "additionalApplianceDetails": {}, + "applianceId": "unique-id-for-non-dimmable-bulb-specific-to-user1" + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOnRequest.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOnRequest.json new file mode 100644 index 0000000000..6883b2fca2 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeControlTurnOnRequest.json @@ -0,0 +1,15 @@ +{ + "header": { + "messageId": "9484BF6A-854E-47B8-86CB-54B22F15740D", + "name": "TurnOnRequest", + "namespace": "Alexa.ConnectedHome.Control", + "payloadVersion": "2" + }, + "payload": { + "accessToken": "1", + "appliance": { + "additionalApplianceDetails": {}, + "applianceId": "unique-id-for-non-dimmable-bulb-specific-to-user1" + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeDiscoveryRequest.json b/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeDiscoveryRequest.json new file mode 100644 index 0000000000..51696a0931 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/alexa-smart-home/AlexaSmartHomeDiscoveryRequest.json @@ -0,0 +1,11 @@ +{ + "header": { + "messageId": "F8752B11-69BB-4246-B923-3BFB27C06C7D", + "name": "DiscoverAppliancesRequest", + "namespace": "Alexa.ConnectedHome.Discovery", + "payloadVersion": "2" + }, + "payload": { + "accessToken": "1" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/apigateway/ApiGatewayAuthorizer.json b/samcli/commands/local/lib/generated_sample_events/events/apigateway/ApiGatewayAuthorizer.json new file mode 100644 index 0000000000..84a4e302f6 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/apigateway/ApiGatewayAuthorizer.json @@ -0,0 +1,5 @@ +{ + "type": "TOKEN", + "authorizationToken": "incoming-client-token", + "methodArn": "arn:aws:execute-api:{{region}}:{{account_id}}:{{restApiId}}/{{stage}}/{{method}}/{{resource}}" +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/apigateway/AwsProxy.json b/samcli/commands/local/lib/generated_sample_events/events/apigateway/AwsProxy.json new file mode 100644 index 0000000000..0f8c704c39 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/apigateway/AwsProxy.json @@ -0,0 +1,62 @@ +{ + "body": "{{body}}", + "resource": "{{resource}}", + "path": "/{{path}}", + "httpMethod": "{{method}}", + "isBase64Encoded": "false", + "queryStringParameters": { + "foo": "bar" + }, + "pathParameters": { + "proxy": "/{{path}}" + }, + "stageVariables": { + "baz": "qux" + }, + "headers": { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Encoding": "gzip, deflate, sdch", + "Accept-Language": "en-US,en;q=0.8", + "Cache-Control": "max-age=0", + "CloudFront-Forwarded-Proto": "https", + "CloudFront-Is-Desktop-Viewer": "true", + "CloudFront-Is-Mobile-Viewer": "false", + "CloudFront-Is-SmartTV-Viewer": "false", + "CloudFront-Is-Tablet-Viewer": "false", + "CloudFront-Viewer-Country": "US", + "Host": "1234567890.execute-api.us-east-1.amazonaws.com", + "Upgrade-Insecure-Requests": "1", + "User-Agent": "Custom User Agent String", + "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", + "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", + "X-Forwarded-For": "127.0.0.1, 127.0.0.2", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "requestContext": { + "accountId": "{{account_id}}", + "resourceId": "123456", + "stage": "{{stage}}", + "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", + "requestTime": "09/Apr/2015:12:34:56 +0000", + "requestTimeEpoch": 1428582896000, + "identity": { + "cognitoIdentityPoolId": null, + "accountId": null, + "cognitoIdentityId": null, + "caller": null, + "accessKey": null, + "sourceIp": "127.0.0.1", + "cognitoAuthenticationType": null, + "cognitoAuthenticationProvider": null, + "userArn": null, + "userAgent": "Custom User Agent String", + "user": null + }, + "path": "/{{stage}}/{{path}}", + "resourcePath": "{{resource}}", + "httpMethod": "{{method}}", + "apiId": "1234567890", + "protocol": "HTTP/1.1" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/batch/BatchGetJob.json b/samcli/commands/local/lib/generated_sample_events/events/batch/BatchGetJob.json new file mode 100644 index 0000000000..109005dfc7 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/batch/BatchGetJob.json @@ -0,0 +1,6 @@ +{ + "jobName": "hello_world", + "jobQueue": "default", + "jobDefinition": "hello_world" +} + diff --git a/samcli/commands/local/lib/generated_sample_events/events/batch/BatchSubmitJob.json b/samcli/commands/local/lib/generated_sample_events/events/batch/BatchSubmitJob.json new file mode 100644 index 0000000000..a7a5ee0a91 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/batch/BatchSubmitJob.json @@ -0,0 +1,3 @@ +{ + "jobId": "38fd08ce-5f5e-434c-8997-6bba5e3f5a74" +} \ No newline at end of file diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudformation/CfnCreateRequest.json b/samcli/commands/local/lib/generated_sample_events/events/cloudformation/CfnCreateRequest.json new file mode 100644 index 0000000000..931ec43abf --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudformation/CfnCreateRequest.json @@ -0,0 +1,16 @@ +{ + "RequestType": "Create", + "ResponseURL": "http://pre-signed-S3-url-for-response", + "StackId": "arn:aws:cloudformation:{{region}}:{{account_id}}:stack/{{stack}}/guid", + "RequestId": "unique id for this create request", + "ResourceType": "Custom::TestResource", + "LogicalResourceId": "MyTestResource", + "ResourceProperties": { + "StackName": "{{stack}}", + "List": [ + "1", + "2", + "3" + ] + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontABTest.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontABTest.json new file mode 100644 index 0000000000..f461799455 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontABTest.json @@ -0,0 +1,36 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "cookie": [ + { + "key": "Cookie", + "value": "SomeCookie=1; AnotherOne=A; X-Experiment-Name=B" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontAccessRequestInResponse.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontAccessRequestInResponse.json new file mode 100644 index 0000000000..24ce5c85a6 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontAccessRequestInResponse.json @@ -0,0 +1,42 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "CloudFront" + } + ] + }, + "clientIp": "2001:cdba::3257:9652", + "uri": "{{uri}}", + "method": "{{method}}" + }, + "response": { + "status": "200", + "statusDescription": "OK", + "headers": { + "x-cache": [ + { + "key": "X-Cache", + "value": "Hello from Cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontHttpRedirect.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontHttpRedirect.json new file mode 100644 index 0000000000..87b3cf65cd --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontHttpRedirect.json @@ -0,0 +1,30 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "user-agent": [ + { + "key": "User-Agent", + "value": "test-agent" + } + ], + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyQueryString.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyQueryString.json new file mode 100644 index 0000000000..47e1572ee2 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyQueryString.json @@ -0,0 +1,37 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "querystring": "auth=test&foo=bar", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "aws-cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyResponseHeader.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyResponseHeader.json new file mode 100644 index 0000000000..3e1b2f9f05 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontModifyResponseHeader.json @@ -0,0 +1,35 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "response": { + "status": "200", + "statusDescription": "OK", + "headers": { + "vary": [ + { + "key": "Vary", + "value": "*" + } + ], + "last-modified": [ + { + "key": "Last-Modified", + "value": "2016-11-25" + } + ], + "x-amz-meta-last-modified": [ + { + "key": "X-Amz-Meta-Last-Modified", + "value": "2016-01-01" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontMultipleRemoteCallsAggregateResponse.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontMultipleRemoteCallsAggregateResponse.json new file mode 100644 index 0000000000..595d8a7150 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontMultipleRemoteCallsAggregateResponse.json @@ -0,0 +1,30 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontNormalizeQuerystringToImproveCacheHit.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontNormalizeQuerystringToImproveCacheHit.json new file mode 100644 index 0000000000..22858b9cb7 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontNormalizeQuerystringToImproveCacheHit.json @@ -0,0 +1,37 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "querystring": "size=LARGE&color=RED", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "aws-cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectOnViewerCountry.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectOnViewerCountry.json new file mode 100644 index 0000000000..d72c39f194 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectOnViewerCountry.json @@ -0,0 +1,30 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "cloudfront-viewer-country": [ + { + "key": "CloudFront-Viewer-Country", + "value": "TW" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectUnauthenticatedUsers.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectUnauthenticatedUsers.json new file mode 100644 index 0000000000..7a63fd5019 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontRedirectUnauthenticatedUsers.json @@ -0,0 +1,24 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "querystring": "foo=bar", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontResponseGeneration.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontResponseGeneration.json new file mode 100644 index 0000000000..74e08dc6ad --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontResponseGeneration.json @@ -0,0 +1,24 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontServeObjectOnViewerDevice.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontServeObjectOnViewerDevice.json new file mode 100644 index 0000000000..7297fd6570 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontServeObjectOnViewerDevice.json @@ -0,0 +1,48 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "cloudfront-is-dektop-viewer": [ + { + "key": "CloudFront-Is-Desktop-Viewer", + "value": "true" + } + ], + "cloudfront-is-mobile-viewer": [ + { + "key": "CloudFront-Is-Mobile-Viewer", + "value": "false" + } + ], + "cloudfront-is-smarttv-viewer": [ + { + "key": "CloudFront-Is-SmartTV-Viewer", + "value": "false" + } + ], + "cloudfront-is-tablet-viewer": [ + { + "key": "CloudFront-Is-Tablet-Viewer", + "value": "false" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontSimpleRemoteCall.json b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontSimpleRemoteCall.json new file mode 100644 index 0000000000..1f5808951c --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cloudfront/CloudFrontSimpleRemoteCall.json @@ -0,0 +1,36 @@ +{ + "Records": [ + { + "cf": { + "config": { + "distributionId": "EXAMPLE" + }, + "request": { + "uri": "{{uri}}", + "method": "{{method}}", + "clientIp": "2001:cdba::3257:9652", + "headers": { + "host": [ + { + "key": "Host", + "value": "d123.cf.net" + } + ], + "user-agent": [ + { + "key": "User-Agent", + "value": "Test Agent" + } + ], + "user-name": [ + { + "key": "User-Name", + "value": "aws-cloudfront" + } + ] + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/codecommit/CodeCommit.json b/samcli/commands/local/lib/generated_sample_events/events/codecommit/CodeCommit.json new file mode 100644 index 0000000000..1901ee6448 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/codecommit/CodeCommit.json @@ -0,0 +1,27 @@ +{ + "Records": [ + { + "awsRegion": "{{region}}", + "codecommit": { + "references": [ + { + "commit": "5c4ef1049f1d27deadbeeff313e0730018be182b", + "ref": "refs/heads/master" + } + ] + }, + "customData": "{{custom_data}}", + "eventId": "5a824061-17ca-46a9-bbf9-114edeadbeef", + "eventName": "TriggerEventTest", + "eventPartNumber": 1, + "eventSource": "aws:codecommit", + "eventSourceARN": "arn:aws:codecommit:{{region}}:{{account_id}}:{{repository}}", + "eventTime": "2016-01-01T23:59:59.000+0000", + "eventTotalParts": 1, + "eventTriggerConfigId": "5a824061-17ca-46a9-bbf9-114edeadbeef", + "eventTriggerName": "{{trigger}}", + "eventVersion": "1.0", + "userIdentityARN": "arn:aws:iam::{{account_id}}:root" + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/codepipeline/CodePipeline.json b/samcli/commands/local/lib/generated_sample_events/events/codepipeline/CodePipeline.json new file mode 100644 index 0000000000..10d93ea61b --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/codepipeline/CodePipeline.json @@ -0,0 +1,45 @@ +{ + "CodePipeline.job": { + "data": { + "artifactCredentials": { + "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", + "sessionToken": "token", + "accessKeyId": "AKIAIOSFODNN7EXAMPLE" + }, + "actionConfiguration": { + "configuration": { + "FunctionName": "my-function", + "UserParameters": "user-parameter-string" + } + }, + "inputArtifacts": [ + { + "revision": "ca2bdeadbeef7d1932acb4977e08c803295d9896", + "name": "input-artifact", + "location": { + "type": "S3", + "s3Location": { + "objectKey": "{{input_key}}", + "bucketName": "{{input_bucket}}" + } + } + } + ], + "outputArtifacts": [ + { + "revision": null, + "name": "output-artifact", + "location": { + "type": "S3", + "s3Location": { + "objectKey": "{{output_key}}", + "bucketName": "{{output_bucket}}" + } + } + } + ] + }, + "id": "c968ef10-6415-4127-80b1-42502218a8c7", + "accountId": "{{account_id}}" + } +} \ No newline at end of file diff --git a/samcli/commands/local/lib/generated_sample_events/events/cognito/CognitoSyncTrigger.json b/samcli/commands/local/lib/generated_sample_events/events/cognito/CognitoSyncTrigger.json new file mode 100644 index 0000000000..ba5b7f5c40 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/cognito/CognitoSyncTrigger.json @@ -0,0 +1,20 @@ +{ + "version": 2, + "eventType": "SyncTrigger", + "region": "{{region}}", + "identityPoolId": "identityPoolId", + "identityId": "identityId", + "datasetName": "datasetName", + "datasetRecords": { + "SampleKey1": { + "oldValue": "oldValue1", + "newValue": "newValue1", + "op": "replace" + }, + "SampleKey2": { + "oldValue": "oldValue2", + "newValue": "newValue2", + "op": "replace" + } + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/config/ConfigurationItemChangeNotification.json b/samcli/commands/local/lib/generated_sample_events/events/config/ConfigurationItemChangeNotification.json new file mode 100644 index 0000000000..6a63989b52 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/config/ConfigurationItemChangeNotification.json @@ -0,0 +1,12 @@ +{ + "invokingEvent": "{\"configurationItem\":{\"configurationItemCaptureTime\":\"2016-10-06T16:46:16.261Z\",\"awsAccountId\":\"{{account_id}}\",\"configurationItemStatus\":\"OK\",\"resourceId\":\"i-00000000\",\"resourceName\":\"foo\",\"configurationStateMd5Hash\":\"8f1ee69b297895a0f8bc5753eca68e96\",\"resourceCreationTime\":\"2016-10-06T16:46:10.489Z\",\"configurationStateId\":0,\"configurationItemVersion\":\"1.2\",\"ARN\":\"arn:aws:ec2:{{region}}:{{account_id}}:instance/i-00000000\",\"awsRegion\":\"{{region}}\",\"availabilityZone\":\"{{region}}\",\"resourceType\":\"AWS::EC2::Instance\",\"tags\":{\"\":\"\"},\"relationships\":[{\"resourceId\":\"eipalloc-00000000\",\"resourceType\":\"AWS::EC2::EIP\",\"name\":\"Is attached to ElasticIp\"}],\"configuration\":{\"\":\"\"}},\"messageType\":\"ConfigurationItemChangeNotification\"}", + "ruleParameters": "{\"\":\"\"}", + "resultToken": "myResultToken", + "eventLeftScope": false, + "executionRoleArn": "arn:aws:iam::{{account_id}}:role/config-role", + "configRuleArn": "arn:aws:config:{{region}}:{{account_id}}:config-rule/config-rule-0123456", + "configRuleName": "change-triggered-config-rule", + "configRuleId": "config-rule-0123456", + "accountId": "{{account_id}}", + "version": "1.0" +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/config/OversizedConfigurationItemChangeNotification.json b/samcli/commands/local/lib/generated_sample_events/events/config/OversizedConfigurationItemChangeNotification.json new file mode 100644 index 0000000000..512ef731dd --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/config/OversizedConfigurationItemChangeNotification.json @@ -0,0 +1,12 @@ +{ + "invokingEvent": "{\"configurationItemSummary\": {\"changeType\": \"UPDATE\",\"configurationItemVersion\": \"1.2\",\"configurationItemCaptureTime\":\"2016-10-06T16:46:16.261Z\",\"configurationStateId\": 0,\"awsAccountId\":\"{{account_id}}\",\"configurationItemStatus\": \"OK\",\"resourceType\": \"AWS::EC2::Instance\",\"resourceId\":\"i-00000000\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:{{region}}:{{account_id}}:instance/i-00000000\",\"awsRegion\": \"{{region}}\",\"availabilityZone\":\"{{region}}\",\"configurationStateMd5Hash\":\"8f1ee69b287895a0f8bc5753eca68e96\",\"resourceCreationTime\":\"2016-10-06T16:46:10.489Z\"},\"messageType\":\"OversizedConfigurationItemChangeNotification\"}", + "ruleParameters": "{\"\":\"\"}", + "resultToken": "myResultToken", + "eventLeftScope": false, + "executionRoleArn": "arn:aws:iam::{{account_id}}:role/config-role", + "configRuleArn": "arn:aws:config:{{region}}:{{account_id}}:config-rule/config-rule-0123456", + "configRuleName": "change-triggered-config-rule", + "configRuleId": "config-rule-0123456", + "accountId": "{{account_id}}", + "version": "1.0" +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/config/PeriodicRule.json b/samcli/commands/local/lib/generated_sample_events/events/config/PeriodicRule.json new file mode 100644 index 0000000000..d927771340 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/config/PeriodicRule.json @@ -0,0 +1,12 @@ +{ + "invokingEvent": "{\"awsAccountId\":\"{{account_id}}\",\"notificationCreationTime\":\"1970-01-01T00:00:00.0Z\",\"messageType\":\"ScheduledNotification\",\"recordVersion\":\"1.0\"}", + "ruleParameters": "{\"myParameterKey\":\"myParameterValue\"}", + "resultToken": "myResultToken", + "eventLeftScope": false, + "executionRoleArn": "arn:aws:iam::{{account_id}}:role/config-role", + "configRuleArn": "arn:aws:config:{{region}}:{{account_id}}:config-rule/config-rule-0123456", + "configRuleName": "periodic-config-rule", + "configRuleId": "config-rule-0123456", + "accountId": "{{account_id}}", + "version": "1.0" +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/dynamodb/DynamoDBUpdate.json b/samcli/commands/local/lib/generated_sample_events/events/dynamodb/DynamoDBUpdate.json new file mode 100644 index 0000000000..fc354e8891 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/dynamodb/DynamoDBUpdate.json @@ -0,0 +1,93 @@ +{ + "Records": [ + { + "eventID": "c4ca4238a0b923820dcc509a6f75849b", + "eventName": "INSERT", + "eventVersion": "1.1", + "eventSource": "aws:dynamodb", + "awsRegion": "{{region}}", + "dynamodb": { + "Keys": { + "Id": { + "N": "101" + } + }, + "NewImage": { + "Message": { + "S": "New item!" + }, + "Id": { + "N": "101" + } + }, + "ApproximateCreationDateTime": 1428537600, + "SequenceNumber": "4421584500000000017450439091", + "SizeBytes": 26, + "StreamViewType": "NEW_AND_OLD_IMAGES" + }, + "eventSourceARN": "arn:aws:dynamodb:{{region}}:{{account_id}}:table/{{table}}/stream/2015-06-27T00:48:05.899" + }, + { + "eventID": "c81e728d9d4c2f636f067f89cc14862c", + "eventName": "MODIFY", + "eventVersion": "1.1", + "eventSource": "aws:dynamodb", + "awsRegion": "{{region}}", + "dynamodb": { + "Keys": { + "Id": { + "N": "101" + } + }, + "NewImage": { + "Message": { + "S": "This item has changed" + }, + "Id": { + "N": "101" + } + }, + "OldImage": { + "Message": { + "S": "New item!" + }, + "Id": { + "N": "101" + } + }, + "ApproximateCreationDateTime": 1428537600, + "SequenceNumber": "4421584500000000017450439092", + "SizeBytes": 59, + "StreamViewType": "NEW_AND_OLD_IMAGES" + }, + "eventSourceARN": "arn:aws:dynamodb:{{region}}:{{account_id}}:table/{{table}}/stream/2015-06-27T00:48:05.899" + }, + { + "eventID": "eccbc87e4b5ce2fe28308fd9f2a7baf3", + "eventName": "REMOVE", + "eventVersion": "1.1", + "eventSource": "aws:dynamodb", + "awsRegion": "{{region}}", + "dynamodb": { + "Keys": { + "Id": { + "N": "101" + } + }, + "OldImage": { + "Message": { + "S": "This item has changed" + }, + "Id": { + "N": "101" + } + }, + "ApproximateCreationDateTime": 1428537600, + "SequenceNumber": "4421584500000000017450439093", + "SizeBytes": 38, + "StreamViewType": "NEW_AND_OLD_IMAGES" + }, + "eventSourceARN": "arn:aws:dynamodb:{{region}}:{{account_id}}:table/{{table}}/stream/2015-06-27T00:48:05.899" + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/events/ScheduledEvent.json b/samcli/commands/local/lib/generated_sample_events/events/events/ScheduledEvent.json new file mode 100644 index 0000000000..b2b3fb6502 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/events/ScheduledEvent.json @@ -0,0 +1,12 @@ +{ + "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c", + "detail-type": "Scheduled Event", + "source": "aws.events", + "account": "{{account-id}}", + "time": "1970-01-01T00:00:00Z", + "region": "{{region}}", + "resources": [ + "arn:aws:events:{{region}}:{{account_id}}:rule/{{rule}}" + ], + "detail": {} +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/kinesis/Kinesis.json b/samcli/commands/local/lib/generated_sample_events/events/kinesis/Kinesis.json new file mode 100644 index 0000000000..b484f1e5a3 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/kinesis/Kinesis.json @@ -0,0 +1,20 @@ +{ + "Records": [ + { + "kinesis": { + "partitionKey": "{{partition}}", + "kinesisSchemaVersion": "1.0", + "data": "{{data}}", + "sequenceNumber": "{{sequence}}", + "approximateArrivalTimestamp": 1428537600.0 + }, + "eventSource": "aws:kinesis", + "eventID": "shardId-000000000000:{{sequence}}", + "invokeIdentityArn": "arn:aws:iam::EXAMPLE", + "eventVersion": "1.0", + "eventName": "aws:kinesis:record", + "eventSourceARN": "arn:aws:kinesis:EXAMPLE", + "awsRegion": "{{region}}" + } + ] +} \ No newline at end of file diff --git a/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehose.json b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehose.json new file mode 100644 index 0000000000..b440909879 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehose.json @@ -0,0 +1,12 @@ +{ + "invocationId": "invocationIdExample", + "deliveryStreamArn": "arn:{{partition}}:kinesis:EXAMPLE", + "region": "{{region}}", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "data": "{{data}}" + } + ] +} \ No newline at end of file diff --git a/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseApachelog.json b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseApachelog.json new file mode 100644 index 0000000000..a52e1be6c0 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseApachelog.json @@ -0,0 +1,11 @@ +{ + "invocationId": "invocationIdExample", + "region": "{{region}}", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "data": "{{data}}" + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseCloudwatchLogsProcessor.json b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseCloudwatchLogsProcessor.json new file mode 100644 index 0000000000..1954e74d6d --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseCloudwatchLogsProcessor.json @@ -0,0 +1,27 @@ +{ + "records": [ + { + "recordId": "49578734086442259037497492980620233840400173390482112514000000", + "data": "H4sIAAAAAAAAADWO0QqCMBiFX2XsWiJFi7wLUW8sIYUuQmLpnxvpJttMQnz3Ztrlxzmc8424BaVIDfmnA+zjID3nlzS5n8IsO8YhtrAYOMg5aURfDUSXNBG1MkEj6liKvjPZQpmWQNoFVf9QpWSdZoJHrNEgFfZvxa8XvoHrGUfMqqWumdHQpDVjtmdvHc91dwdn71p/vVngmqBVD616PgoolC/Ga0SBNJoi8USVWWKczM8oYhKoULDBUzF9Aeua5yHsAAAA", + "approximateArrivalTimestamp": 1510254469499 + }, + { + "recordId": "49578734086442259037497492980621442766219788363254202370000000", + "data": "H4sIAAAAAAAAAJWRTWsbMRCG/8ueLZjRjL5yc9NNLnZDapemlFAkrTYstb3Lep0Qgv97x00KgTSHnAQzmkeP3nmqtmW/j3dl/TiU6qz6PF/Pfy3r1Wp+WVezqn/YlVHK2pK3Hr0Jxkt5099djv1hkE7uh0eVHzZqE7epiarb3fe/ixzDYVJoELRhssYQqsXLlEJ3jd8//biy4QYWz7jVNJa4/TDveQwV+qsada0v/HnthLg/pH0eu2Hq+t1Ft5nKuK/Ofn4EvnpDUAu7Xi6/LL9en3/z1e1f7fq+7KYT+qnqGrEnsi54AGS2wbHWxjCjoWAYGawmzawByIG3Dp0JzjOxsaI8dbKJKW4l1BcTdgg+zP5tSPCeQ/Bso/I+o+I2kUptjgrRlQyasslUHWdvZRwGJ4+HYJGCtiKgQTYKSJ4gODLgAkpFk3f0rkyA1zLGSsvoVsVCRTFakUkNqKxt1IyFc8T/y0gEmoHZo5a/W9HhU0TeWHMyIJaoQC6zDvC+DL6WSW3MqZSkiolJcWoalWybJSNIJTXcRgjV8fb4BwwLrNzwAgAA", + "approximateArrivalTimestamp": 1510254473773 + }, + { + "recordId": "49578734086442259037497492980622651692039402992428908546000000", + "data": "H4sIAAAAAAAAAJWRbWsbMQyA/8t9jkGSJdnut2zLCiXZyJKyZaMM352vHEty4e7SUkr++9yXwUbXD8Vgg2w9eizdF7s0DPE6re8OqTgrPkzX05+L2Wo1PZ8Vk6K73ac+h0mtV49egvgc3nbX5313POSbqjvcmep2a7ZxV9bRtPub7lfKx+E4GhQEErYqYtHMn7MMuiV+fbf5rOEbzJ9wq7FPcfdm3lOaNReXyws/3cw2fvk9A4djOVR9exjbbv+x3Y6pH4qzH29hr14QzFzXi8WnxZfl+0tfXD1az27SfnxA3xdtneWtVRc8ADJrcEwkwoxigzAyiBNxzkJuIxGrei+g3gbgrDy2eRBj3OWePpuwQ/Bh8mdAGR+J69pJMFXKihwTGJ+aYJArpkjYQB2K0+SljMPgyFIIijaQgs2BAMEyexbns1NeoqpsCV+VCfCPTOVLLgUMU4h5S5UpE4BRm6ROqCEF/r8MExBDro3ED0XBMigFVM0iQlkRvZLml9a/LoN/yzSYKoIKTOmVTf6VNTHZxkjTIElkqlCL09XpN5PgkxrvAgAA", + "approximateArrivalTimestamp": 1510254474027 + }, + { + "recordId": "49578734086442259037497492980623860617859017621603614722000000", + "data": "H4sIAAAAAAAAAJWRW28aQQyF/8s+M9J47LHHeaMtzUOhEQXSVlVUDctstCqwCJZEUcR/r3OpFCnNQ17mcjw+8+n4vtqUwyFfl/ndrlRn1afhfPh7MprNhuejalB1t9uyNzkwJk6QosZk8rq7Pt93x51V6m535+rbtVvnzXKVXbu96f4U23bH3kEEHyIhx4jgxs9dDmQK3z/8vGD94cdPdrN+X/Lm3X5PbcHp5QLkYrqYLC6/mOHhuDzU+3bXt932c7vuy/5Qnf16j/fslYMb83wy+Tr5Nv24SNXVI/Xopmz7B+v7ql0ZPCKLJu+BiFUohBiJIKJGAvIkSTgpsU8aVBNangymsCH3rQ2izxvL9JmEBOzh4N+AzL6gX3JD7CLn4kg8OiVduahNkIa0BtbqNHgNI6AS0P5kQA3sUcA4IDCElCBKwgdgiCoI+CaM+pcwbAVfN8F5r2owGV0OdpWkS8kp52a1/D8MBR8sDUoQKDIbDnqlhAgQLTMWz8YbRQT92zDwEkbIQ10YHUZbKGfvUmrAIWodih2btKpOV6e/zXGIX+8CAAA=", + "approximateArrivalTimestamp": 1510254474388 + } + ], + "region": "{{region}}", + "deliveryStreamArn": "arn:aws:firehose:{{region}}:{{account_id}}:deliverystream/copy-cwl-lambda-invoke-input-151025436553-Firehose-8KILJ01Q5OBN", + "invocationId": "a7234216-12b6-4bc0-96d7-82606c0e80cf" +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseStreamsAsSource.json b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseStreamsAsSource.json new file mode 100644 index 0000000000..7e38cb7f1e --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseStreamsAsSource.json @@ -0,0 +1,19 @@ +{ + "invocationId": "invocationIdExample", + "deliverySteamArn": "arn:{{partition}}:kinesis:EXAMPLE", + "region": "{{region}}", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "kinesisRecordMetadata": { + "sequenceNumber": "{{sequence}}", + "subsequenceNumber": "123456", + "partitionKey": "{{partition}}", + "shardId": "shardId-000000000000", + "approximateArrivalTimestamp": 1495072949453 + }, + "data": "{{data}}" + } + ] +} \ No newline at end of file diff --git a/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseSyslog.json b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseSyslog.json new file mode 100644 index 0000000000..1e06518f6d --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/kinesis/KinesisFirehoseSyslog.json @@ -0,0 +1,16 @@ +{ + "invocationId": "fir", + "region": "{{region}}", + "records": [ + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": 1495072949453, + "data": "{{data}}" + }, + { + "recordId": "49546986683135544286507457936321625675700192471156785154", + "approximateArrivalTimestamp": "2012-04-23T18:25:43.511Z", + "data": "{{data}}" + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/lex/LexBookCar.json b/samcli/commands/local/lib/generated_sample_events/events/lex/LexBookCar.json new file mode 100644 index 0000000000..161303f758 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/lex/LexBookCar.json @@ -0,0 +1,23 @@ +{ + "messageVersion": "1.0", + "invocationSource": "DialogCodeHook", + "userId": "John", + "sessionAttributes": {}, + "bot": { + "name": "BookTrip", + "alias": "$LATEST", + "version": "$LATEST" + }, + "outputDialogMode": "Text", + "currentIntent": { + "name": "BookCar", + "slots": { + "PickUpCity": "Chicago", + "PickUpDate": "2030-11-08", + "ReturnDate": "2030-11-08", + "CarType": "economy", + "DriverAge": 21 + }, + "confirmationStatus": "None" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/lex/LexBookHotel.json b/samcli/commands/local/lib/generated_sample_events/events/lex/LexBookHotel.json new file mode 100644 index 0000000000..a8c725eb07 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/lex/LexBookHotel.json @@ -0,0 +1,22 @@ +{ + "messageVersion": "1.0", + "invocationSource": "DialogCodeHook", + "userId": "John", + "sessionAttributes": {}, + "bot": { + "name": "BookTrip", + "alias": "$LATEST", + "version": "$LATEST" + }, + "outputDialogMode": "Text", + "currentIntent": { + "name": "BookHotel", + "slots": { + "Location": "Chicago", + "CheckInDate": "2030-11-08", + "Nights": 4, + "RoomType": "queen" + }, + "confirmationStatus": "None" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/lex/LexMakeAppointment.json b/samcli/commands/local/lib/generated_sample_events/events/lex/LexMakeAppointment.json new file mode 100644 index 0000000000..3e1985ea86 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/lex/LexMakeAppointment.json @@ -0,0 +1,21 @@ +{ + "messageVersion": "1.0", + "invocationSource": "DialogCodeHook", + "userId": "John", + "sessionAttributes": {}, + "bot": { + "name": "MakeAppointment", + "alias": "$LATEST", + "version": "$LATEST" + }, + "outputDialogMode": "Text", + "currentIntent": { + "name": "MakeAppointment", + "slots": { + "AppointmentType": "whitening", + "Date": "2030-11-08", + "Time": "10:00" + }, + "confirmationStatus": "None" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/lex/LexOrderFlowers.json b/samcli/commands/local/lib/generated_sample_events/events/lex/LexOrderFlowers.json new file mode 100644 index 0000000000..5f0d0aee69 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/lex/LexOrderFlowers.json @@ -0,0 +1,21 @@ +{ + "messageVersion": "1.0", + "invocationSource": "DialogCodeHook", + "userId": "John", + "sessionAttributes": {}, + "bot": { + "name": "OrderFlowers", + "alias": "$LATEST", + "version": "$LATEST" + }, + "outputDialogMode": "Text", + "currentIntent": { + "name": "OrderFlowers", + "slots": { + "FlowerType": "lilies", + "PickupDate": "2030-11-08", + "PickupTime": "10:00" + }, + "confirmationStatus": "None" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/logs/CloudwatchLogs.json b/samcli/commands/local/lib/generated_sample_events/events/logs/CloudwatchLogs.json new file mode 100644 index 0000000000..aa184c1d01 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/logs/CloudwatchLogs.json @@ -0,0 +1,5 @@ +{ + "awslogs": { + "data": "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA==" + } +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/rekognition/RekognitionS3Request.json b/samcli/commands/local/lib/generated_sample_events/events/rekognition/RekognitionS3Request.json new file mode 100644 index 0000000000..7204b90bbf --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/rekognition/RekognitionS3Request.json @@ -0,0 +1,38 @@ +{ + "Records": [ + { + "eventVersion": "2.0", + "eventSource": "aws:s3", + "awsRegion": "{{region}}", + "eventTime": "1970-01-01T00:00:00.000Z", + "eventName": "ObjectCreated:Put", + "userIdentity": { + "principalId": "EXAMPLE" + }, + "requestParameters": { + "sourceIPAddress": "127.0.0.1" + }, + "responseElements": { + "x-amz-request-id": "EXAMPLE123456789", + "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH" + }, + "s3": { + "s3SchemaVersion": "1.0", + "configurationId": "testConfigRule", + "bucket": { + "name": "{{bucket}}", + "ownerIdentity": { + "principalId": "EXAMPLE" + }, + "arn": "arn:aws:s3:::{{bucket}}" + }, + "object": { + "key": "{{key}}", + "size": 1024, + "eTag": "0123456789abcdef0123456789abcdef", + "sequencer": "0A1B2C3D4E5F678901" + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/s3/S3Delete.json b/samcli/commands/local/lib/generated_sample_events/events/s3/S3Delete.json new file mode 100644 index 0000000000..f544a46218 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/s3/S3Delete.json @@ -0,0 +1,36 @@ +{ + "Records": [ + { + "eventVersion": "2.0", + "eventSource": "aws:s3", + "awsRegion": "{{region}}", + "eventTime": "1970-01-01T00:00:00.000Z", + "eventName": "ObjectRemoved:Delete", + "userIdentity": { + "principalId": "EXAMPLE" + }, + "requestParameters": { + "sourceIPAddress": "127.0.0.1" + }, + "responseElements": { + "x-amz-request-id": "EXAMPLE123456789", + "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH" + }, + "s3": { + "s3SchemaVersion": "1.0", + "configurationId": "testConfigRule", + "bucket": { + "name": "{{bucket}}", + "ownerIdentity": { + "principalId": "EXAMPLE" + }, + "arn": "arn:aws:s3:::{{bucket}}" + }, + "object": { + "key": "{{key}}", + "sequencer": "0A1B2C3D4E5F678901" + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/s3/S3Put.json b/samcli/commands/local/lib/generated_sample_events/events/s3/S3Put.json new file mode 100644 index 0000000000..7204b90bbf --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/s3/S3Put.json @@ -0,0 +1,38 @@ +{ + "Records": [ + { + "eventVersion": "2.0", + "eventSource": "aws:s3", + "awsRegion": "{{region}}", + "eventTime": "1970-01-01T00:00:00.000Z", + "eventName": "ObjectCreated:Put", + "userIdentity": { + "principalId": "EXAMPLE" + }, + "requestParameters": { + "sourceIPAddress": "127.0.0.1" + }, + "responseElements": { + "x-amz-request-id": "EXAMPLE123456789", + "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH" + }, + "s3": { + "s3SchemaVersion": "1.0", + "configurationId": "testConfigRule", + "bucket": { + "name": "{{bucket}}", + "ownerIdentity": { + "principalId": "EXAMPLE" + }, + "arn": "arn:aws:s3:::{{bucket}}" + }, + "object": { + "key": "{{key}}", + "size": 1024, + "eTag": "0123456789abcdef0123456789abcdef", + "sequencer": "0A1B2C3D4E5F678901" + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/ses/SesEmailReceiving.json b/samcli/commands/local/lib/generated_sample_events/events/ses/SesEmailReceiving.json new file mode 100644 index 0000000000..dead427cc5 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/ses/SesEmailReceiving.json @@ -0,0 +1,97 @@ +{ + "Records": [ + { + "eventSource": "aws:ses", + "eventVersion": "1.0", + "ses": { + "mail": { + "commonHeaders": { + "date": "Wed, 7 Oct 2015 12:34:56 -0700", + "from": [ + "Jane Doe " + ], + "messageId": "<0123456789example.com>", + "returnPath": "janedoe@example.com", + "subject": "Test Subject", + "to": [ + "johndoe@example.com" + ] + }, + "destination": [ + "johndoe@example.com" + ], + "headers": [ + { + "name": "Return-Path", + "value": "" + }, + { + "name": "Received", + "value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.{{region}}.amazonaws.com with SMTP id o3vrnil0e2ic28trm7dfhrc2v0cnbeccl4nbp0g1 for johndoe@example.com; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)" + }, + { + "name": "DKIM-Signature", + "value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; h=mime-version:from:date:message-id:subject:to:content-type; bh=jX3F0bCAI7sIbkHyy3mLYO28ieDQz2R0P8HwQkklFj4=; b=sQwJ+LMe9RjkesGu+vqU56asvMhrLRRYrWCbVt6WJulueecwfEwRf9JVWgkBTKiL6m2hr70xDbPWDhtLdLO+jB3hzjVnXwK3pYIOHw3vxG6NtJ6o61XSUwjEsp9tdyxQjZf2HNYee873832l3K1EeSXKzxYk9Pwqcpi3dMC74ct9GukjIevf1H46hm1L2d9VYTL0LGZGHOAyMnHmEGB8ZExWbI+k6khpurTQQ4sp4PZPRlgHtnj3Zzv7nmpTo7dtPG5z5S9J+L+Ba7dixT0jn3HuhaJ9b+VThboo4YfsX9PMNhWWxGjVksSFOcGluPO7QutCPyoY4gbxtwkN9W69HA==" + }, + { + "name": "MIME-Version", + "value": "1.0" + }, + { + "name": "From", + "value": "Jane Doe " + }, + { + "name": "Date", + "value": "Wed, 7 Oct 2015 12:34:56 -0700" + }, + { + "name": "Message-ID", + "value": "<0123456789example.com>" + }, + { + "name": "Subject", + "value": "Test Subject" + }, + { + "name": "To", + "value": "johndoe@example.com" + }, + { + "name": "Content-Type", + "value": "text/plain; charset=UTF-8" + } + ], + "headersTruncated": false, + "messageId": "o3vrnil0e2ic28trm7dfhrc2v0clambda4nbp0g1", + "source": "janedoe@example.com", + "timestamp": "1970-01-01T00:00:00.000Z" + }, + "receipt": { + "action": { + "functionArn": "arn:aws:lambda:{{region}}:{{account_id}}:function:Example", + "invocationType": "Event", + "type": "Lambda" + }, + "dkimVerdict": { + "status": "PASS" + }, + "processingTimeMillis": 574, + "recipients": [ + "johndoe@example.com" + ], + "spamVerdict": { + "status": "PASS" + }, + "spfVerdict": { + "status": "PASS" + }, + "timestamp": "1970-01-01T00:00:00.000Z", + "virusVerdict": { + "status": "PASS" + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/sns/Sns.json b/samcli/commands/local/lib/generated_sample_events/events/sns/Sns.json new file mode 100644 index 0000000000..aa0b9acd99 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/sns/Sns.json @@ -0,0 +1,31 @@ +{ + "Records": [ + { + "EventSource": "aws:sns", + "EventVersion": "1.0", + "EventSubscriptionArn": "arn:aws:sns:{{region}}:{{accountId}}:{{topic}}", + "Sns": { + "Type": "Notification", + "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", + "TopicArn": "arn:aws:sns:{{region}}:{{account_id}}:{{topic}}", + "Subject": "{{subject}}", + "Message": "{{message}}", + "Timestamp": "1970-01-01T00:00:00.000Z", + "SignatureVersion": "1", + "Signature": "EXAMPLE", + "SigningCertUrl": "EXAMPLE", + "UnsubscribeUrl": "EXAMPLE", + "MessageAttributes": { + "Test": { + "Type": "String", + "Value": "TestString" + }, + "TestBinary": { + "Type": "Binary", + "Value": "TestBinary" + } + } + } + } + ] +} diff --git a/samcli/commands/local/lib/generated_sample_events/events/sqs/Sqs.json b/samcli/commands/local/lib/generated_sample_events/events/sqs/Sqs.json new file mode 100644 index 0000000000..44efa925f3 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/sqs/Sqs.json @@ -0,0 +1,20 @@ +{ + "Records": [ + { + "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78", + "receiptHandle": "MessageReceiptHandle", + "body": "Hello from SQS!", + "attributes": { + "ApproximateReceiveCount": "1", + "SentTimestamp": "1523232000000", + "SenderId": "{{account_id}}", + "ApproximateFirstReceiveTimestamp": "1523232000001" + }, + "messageAttributes": {}, + "md5OfBody": "7b270e59b47ff90a553787216d55d91d", + "eventSource": "aws:sqs", + "eventSourceARN": "arn:{{partition}}:sqs:{{region}}:{{account_id}}:{{queue_name}}", + "awsRegion": "{{region}}" + } + ] + } \ No newline at end of file diff --git a/samcli/commands/local/lib/generated_sample_events/events/stepfunctions/StepFunctionsError.json b/samcli/commands/local/lib/generated_sample_events/events/stepfunctions/StepFunctionsError.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/samcli/commands/local/lib/generated_sample_events/events/stepfunctions/StepFunctionsError.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/samcli/commands/local/generate_event/dynamodb/__init__.py b/tests/integration/local/generate_event/__init__.py similarity index 100% rename from samcli/commands/local/generate_event/dynamodb/__init__.py rename to tests/integration/local/generate_event/__init__.py diff --git a/tests/integration/local/generate_event/test_cli_integ.py b/tests/integration/local/generate_event/test_cli_integ.py new file mode 100644 index 0000000000..2bad1fb072 --- /dev/null +++ b/tests/integration/local/generate_event/test_cli_integ.py @@ -0,0 +1,19 @@ +from unittest import TestCase +from subprocess import Popen +import os + + +class Test_EventGeneration_Integ(TestCase): + + def test_generate_event_substitution(self): + process = Popen([Test_EventGeneration_Integ._get_command(), "local", "generate-event", "s3", "put"]) + return_code = process.wait() + self.assertEquals(return_code, 0) + + @staticmethod + def _get_command(): + command = "sam" + if os.getenv("SAM_CLI_DEV"): + command = "samdev" + + return command diff --git a/tests/unit/cli/test_main.py b/tests/unit/cli/test_main.py index d7009498ee..0e3568fe39 100644 --- a/tests/unit/cli/test_main.py +++ b/tests/unit/cli/test_main.py @@ -25,5 +25,5 @@ def test_cli_some_command(self): def test_cli_with_debug(self): runner = CliRunner() - result = runner.invoke(cli, ["local", "generate-event", "s3", "--debug"]) + result = runner.invoke(cli, ["local", "generate-event", "s3", "put", "--debug"]) self.assertEquals(result.exit_code, 0) diff --git a/tests/unit/commands/local/generate_event/api/__init__.py b/tests/unit/commands/local/generate_event/api/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/commands/local/generate_event/api/test_cli.py b/tests/unit/commands/local/generate_event/api/test_cli.py deleted file mode 100644 index cb8d16f9e2..0000000000 --- a/tests/unit/commands/local/generate_event/api/test_cli.py +++ /dev/null @@ -1,23 +0,0 @@ -from unittest import TestCase -from mock import patch - -from samcli.commands.local.generate_event.api.cli import do_cli as api_cli - - -class TestCli(TestCase): - - @patch("samcli.commands.local.generate_event.api.cli.json") - @patch("samcli.commands.local.generate_event.api.cli.click") - @patch("samcli.commands.local.generate_event.api.cli.generate_api_event") - def test_generate_schedule_event(self, api_event_patch, click_patch, json_patch): - json_patch.dumps.return_value = "This to be echoed by click" - - method = "method" - body = "body" - resource = "resource" - path = "path" - - api_cli(ctx=None, method=method, body=body, resource=resource, path=path) - - api_event_patch.assert_called_once_with(method, body, resource, path) - click_patch.echo.assert_called_once_with("This to be echoed by click") diff --git a/tests/unit/commands/local/generate_event/dynamodb/__init__.py b/tests/unit/commands/local/generate_event/dynamodb/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/commands/local/generate_event/dynamodb/test_cli.py b/tests/unit/commands/local/generate_event/dynamodb/test_cli.py deleted file mode 100644 index 56a45f5d19..0000000000 --- a/tests/unit/commands/local/generate_event/dynamodb/test_cli.py +++ /dev/null @@ -1,20 +0,0 @@ -from unittest import TestCase -from mock import patch - -from samcli.commands.local.generate_event.dynamodb.cli import do_cli as dynamodb_cli - - -class TestCli(TestCase): - - @patch("samcli.commands.local.generate_event.dynamodb.cli.json") - @patch("samcli.commands.local.generate_event.dynamodb.cli.click") - @patch("samcli.commands.local.generate_event.dynamodb.cli.generate_dynamodb_event") - def test_generate_schedule_event(self, dynamodb_event_patch, click_patch, json_patch): - json_patch.dumps.return_value = "This to be echoed by click" - - region = "region" - - dynamodb_cli(ctx=None, region=region) - - dynamodb_event_patch.assert_called_once_with(region) - click_patch.echo.assert_called_once_with("This to be echoed by click") diff --git a/tests/unit/commands/local/generate_event/kinesis/__init__.py b/tests/unit/commands/local/generate_event/kinesis/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/commands/local/generate_event/kinesis/test_cli.py b/tests/unit/commands/local/generate_event/kinesis/test_cli.py deleted file mode 100644 index ae91e3fb70..0000000000 --- a/tests/unit/commands/local/generate_event/kinesis/test_cli.py +++ /dev/null @@ -1,25 +0,0 @@ -from unittest import TestCase -from mock import patch - -from samcli.commands.local.generate_event.kinesis.cli import do_cli as kinesis_cli - - -class TestCli(TestCase): - - @patch("samcli.commands.local.generate_event.kinesis.cli.json") - @patch("samcli.commands.local.generate_event.kinesis.cli.click") - @patch("samcli.commands.local.generate_event.kinesis.cli.generate_kinesis_event") - def test_generate_schedule_event(self, kinesis_event_patch, click_patch, json_patch): - json_patch.dumps.return_value = "This to be echoed by click" - - region = "region" - partition = "partition" - sequence = "sequence" - data = "data" - - data_base64 = b"ZGF0YQ==" - - kinesis_cli(ctx=None, region=region, partition=partition, sequence=sequence, data=data) - - kinesis_event_patch.assert_called_once_with(region, partition, sequence, data_base64) - click_patch.echo.assert_called_once_with("This to be echoed by click") diff --git a/tests/unit/commands/local/generate_event/s3/__init__.py b/tests/unit/commands/local/generate_event/s3/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/commands/local/generate_event/s3/test_cli.py b/tests/unit/commands/local/generate_event/s3/test_cli.py deleted file mode 100644 index da2d86035d..0000000000 --- a/tests/unit/commands/local/generate_event/s3/test_cli.py +++ /dev/null @@ -1,22 +0,0 @@ -from unittest import TestCase -from mock import patch - -from samcli.commands.local.generate_event.s3.cli import do_cli as s3_cli - - -class TestCli(TestCase): - - @patch("samcli.commands.local.generate_event.s3.cli.json") - @patch("samcli.commands.local.generate_event.s3.cli.click") - @patch("samcli.commands.local.generate_event.s3.cli.generate_s3_event") - def test_generate_schedule_event(self, s3_event_patch, click_patch, json_patch): - json_patch.dumps.return_value = "This to be echoed by click" - - region = "region" - bucket = "bucket" - key = "key" - - s3_cli(ctx=None, region=region, bucket=bucket, key=key) - - s3_event_patch.assert_called_once_with(region, bucket, key) - click_patch.echo.assert_called_once_with("This to be echoed by click") diff --git a/tests/unit/commands/local/generate_event/schedule/__init__.py b/tests/unit/commands/local/generate_event/schedule/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/commands/local/generate_event/schedule/test_cli.py b/tests/unit/commands/local/generate_event/schedule/test_cli.py deleted file mode 100644 index 0bd874608a..0000000000 --- a/tests/unit/commands/local/generate_event/schedule/test_cli.py +++ /dev/null @@ -1,20 +0,0 @@ -from unittest import TestCase -from mock import patch - -from samcli.commands.local.generate_event.schedule.cli import do_cli as schedule_cli - - -class TestCli(TestCase): - - @patch("samcli.commands.local.generate_event.schedule.cli.json") - @patch("samcli.commands.local.generate_event.schedule.cli.click") - @patch("samcli.commands.local.generate_event.schedule.cli.generate_schedule_event") - def test_generate_schedule_event(self, schedule_event_patch, click_patch, json_patch): - json_patch.dumps.return_value = "This to be echoed by click" - - region = "us-east-1" - - schedule_cli(ctx=None, region=region) - - schedule_event_patch.assert_called_once_with(region) - click_patch.echo.assert_called_once_with("This to be echoed by click") diff --git a/tests/unit/commands/local/generate_event/sns/__init__.py b/tests/unit/commands/local/generate_event/sns/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/unit/commands/local/generate_event/sns/test_cli.py b/tests/unit/commands/local/generate_event/sns/test_cli.py deleted file mode 100644 index a3091c6a98..0000000000 --- a/tests/unit/commands/local/generate_event/sns/test_cli.py +++ /dev/null @@ -1,22 +0,0 @@ -from unittest import TestCase -from mock import patch - -from samcli.commands.local.generate_event.sns.cli import do_cli as sns_cli - - -class TestCli(TestCase): - - @patch("samcli.commands.local.generate_event.sns.cli.json") - @patch("samcli.commands.local.generate_event.sns.cli.click") - @patch("samcli.commands.local.generate_event.sns.cli.generate_sns_event") - def test_generate_schedule_event(self, sns_event_patch, click_patch, json_patch): - json_patch.dumps.return_value = "This to be echoed by click" - - message = "message" - topic = "topic" - subject = "subject" - - sns_cli(ctx=None, message=message, topic=topic, subject=subject) - - sns_event_patch.assert_called_once_with(message, topic, subject) - click_patch.echo.assert_called_once_with("This to be echoed by click") diff --git a/tests/unit/commands/local/generate_event/test_event_generation.py b/tests/unit/commands/local/generate_event/test_event_generation.py new file mode 100644 index 0000000000..4d1e08125e --- /dev/null +++ b/tests/unit/commands/local/generate_event/test_event_generation.py @@ -0,0 +1,157 @@ +from unittest import TestCase +from mock import Mock +from mock import patch + +from samcli.commands.local.lib.generated_sample_events import events +from samcli.commands.local.generate_event.event_generation import ServiceCommand +from samcli.commands.local.generate_event.event_generation import EventTypeSubCommand + + +class TestEvents(TestCase): + + def setUp(self): + self.values_to_sub = {"hello": "world"} + + def test_base64_encoding(self): + tags = {"hello": {"encoding": "base64"}} + e = events.Events().encode(tags, 'encoding', self.values_to_sub) + self.assertEqual(e, {"hello": "d29ybGQ="}) + + def test_url_encoding(self): + tags = {"hello": {"encoding": "url"}} + e = events.Events().encode(tags, 'encoding', self.values_to_sub) + self.assertEqual(e, {"hello": "world"}) + + def test_if_encoding_is_none(self): + tags = {"hello": {"encoding": "None"}} + e = events.Events().encode(tags, 'encoding', self.values_to_sub) + self.assertEqual(e, {"hello": "world"}) + + def test_if_tags_is_empty(self): + tags = {} + e = events.Events().encode(tags, 'encoding', {}) + self.assertEqual(e, {}) + + def test_if_tags_is_two_or_more(self): + tags = {"hello": {"encoding": "base64"}, "hi": {"encoding": "url"}, "bop": {"encoding": "None"}} + values_to_sub = {"bop": "dop", "hello": "world", "hi": "yo"} + e = events.Events().encode(tags, 'encoding', values_to_sub) + self.assertEqual(e, {"bop": "dop", "hello": "d29ybGQ=", "hi": "yo"}) + + +class TestServiceCommand(TestCase): + + def setUp(self): + self.service_cmd_name = "myservice" + self.event_type_name = "myevent" + self.all_cmds = {"hello": "world", "hi": "you"} + self.events_lib_mock = Mock() + self.events_lib_mock.event_mapping = self.all_cmds + self.s = ServiceCommand(self.events_lib_mock) + + def test_init_has_correct_all_cmds(self): + self.assertEqual(self.s.all_cmds, self.all_cmds) + + def test_init_events_lib_is_not_valid(self): + with self.assertRaises(ValueError): + ServiceCommand(events_lib=None) + + def test_init_events_lib_is_valid(self): + s = ServiceCommand(self.events_lib_mock) + self.assertEqual(s.events_lib, self.events_lib_mock) + + def test_get_command_returns_none_when_not_in_all_cmds(self): + cmd_name = "howdy" + e = self.s.get_command(None, cmd_name) + self.assertIsNone(e) + + def test_list_commands_must_return_commands_name(self): + expected = self.s.list_commands(ctx=None) + self.assertEqual(expected, ['hello', 'hi']) + + def test_get_command_return_value(self): + command_name = "hello" + output = self.s.get_command(None, command_name) + self.assertEqual(output.top_level_cmd_name, "hello") + self.assertEqual(output.events_lib, self.events_lib_mock) + self.assertEqual(output.subcmd_definition, "world") + + +class TestEventTypeSubCommand(TestCase): + + def setUp(self): + self.service_cmd_name = "myservice" + self.event_type_name = "myevent" + self.all_cmds = '{"hello": "world", "hi": "you"}' + self.events_lib_mock = Mock() + self.s = EventTypeSubCommand(self.events_lib_mock, self.service_cmd_name, self.all_cmds) + + def test_subcommand_accepts_events_lib(self): + events_lib = Mock() + events_lib.expose_event_metadata.return_value = self.all_cmds + s = EventTypeSubCommand(events_lib, self.service_cmd_name, self.all_cmds) + self.assertEqual(s.events_lib, events_lib) + + def test_subcommand_accepts_top_level_cmd_name(self): + top_lvl_cmd = "myservice" + self.assertEqual(top_lvl_cmd, self.service_cmd_name) + + def test_subcommand_accepts_subcmd_definition(self): + self.assertEqual(self.s.subcmd_definition, self.all_cmds) + + def test_subcommand_get_accepts_cmd_name_returns_none(self): + subcmd_definition = '{"hello": { "tags : { "world" }}}' + s = EventTypeSubCommand(self.events_lib_mock, self.service_cmd_name, subcmd_definition) + e = s.get_command(None, "heyyo") + self.assertIsNone(e) + + @patch("samcli.cli.options.click") + @patch("samcli.commands.local.generate_event.event_generation.functools") + @patch("samcli.commands.local.generate_event.event_generation.click") + def test_subcommand_get_command_return_value(self, click_mock, functools_mock, options_click_mock): + all_commands = {"hi": {"help": "Generates a hello Event", "tags": {}}} + command_object_mock = Mock() + click_mock.Command.return_value = command_object_mock + option_mock = Mock() + options_click_mock.Option.return_value = option_mock + callback_object_mock = Mock() + functools_mock.partial.return_value = callback_object_mock + s = EventTypeSubCommand(self.events_lib_mock, "hello", all_commands) + s.get_command(None, "hi") + click_mock.Command.assert_called_once_with(name="hi", + help="Generates a hello Event", + params=[], + callback=callback_object_mock) + + def test_subcommand_list_return_value(self): + subcmd_def = {"hello": "world", "hi": "you"} + self.events_lib_mock.expose_event_metadata.return_value = subcmd_def + s = EventTypeSubCommand(self.events_lib_mock, "hello", subcmd_def) + expected = ['hello', 'hi'] + self.assertEquals(s.list_commands(ctx=None), expected) + + def test_must_print_sample_event_json(self): + event_json = '{"hello": "world"}' + self.events_lib_mock.generate_event.return_value = event_json + s = EventTypeSubCommand(self.events_lib_mock, "hello", event_json) + event = s.cmd_implementation(self.events_lib_mock, + self.service_cmd_name, + self.event_type_name, + {}) + self.events_lib_mock.generate_event.assert_called_with(self.service_cmd_name, + self.event_type_name, + {}) + self.assertEqual(event, event_json) + + def test_must_accept_keyword_args(self): + event_json = '{"hello": "world"}' + self.events_lib_mock.generate_event.return_value = event_json + s = EventTypeSubCommand(self.events_lib_mock, "hello", event_json) + event = s.cmd_implementation(self.events_lib_mock, + self.service_cmd_name, + self.event_type_name, + key="value") + self.events_lib_mock.generate_event.assert_called_with(self.service_cmd_name, + self.event_type_name, + {"key": "value"}) + self.assertEqual(event, event_json) diff --git a/tests/unit/commands/local/lib/test_events.py b/tests/unit/commands/local/lib/test_events.py deleted file mode 100644 index dd12eec2ba..0000000000 --- a/tests/unit/commands/local/lib/test_events.py +++ /dev/null @@ -1,286 +0,0 @@ -from unittest import TestCase - -from samcli.commands.local.lib.events import generate_api_event, generate_dynamodb_event, generate_kinesis_event, \ - generate_schedule_event, generate_sns_event, generate_s3_event - - -class TestGeneratedEvent(TestCase): - - def test_s3_event(self): - actual_event = generate_s3_event("us-east-1", "bucket", "key") - - expected_event = { - "Records": [{ - "eventVersion": "2.0", - "eventTime": "1970-01-01T00:00:00.000Z", - "requestParameters": { - "sourceIPAddress": "127.0.0.1" - }, - "s3": { - "configurationId": "testConfigRule", - "object": { - "eTag": "0123456789abcdef0123456789abcdef", - "sequencer": "0A1B2C3D4E5F678901", - "key": "key", - "size": 1024 - }, - "bucket": { - "arn": "arn:aws:s3:::bucket", - "name": "bucket", - "ownerIdentity": { - "principalId": "EXAMPLE" - } - }, - "s3SchemaVersion": "1.0" - }, - "responseElements": { - "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH", - "x-amz-request-id": "EXAMPLE123456789" - }, - "awsRegion": "us-east-1", - "eventName": "ObjectCreated:Put", - "userIdentity": { - "principalId": "EXAMPLE" - }, - "eventSource": "aws:s3" - }] - } - - self.assertEquals(actual_event, expected_event) - - def test_sns_event(self): - actual_event = generate_sns_event("message", "topic", "subject") - - expected_event = { - "Records": [{ - "EventVersion": "1.0", - "EventSubscriptionArn": "arn:aws:sns:EXAMPLE", - "EventSource": "aws:sns", - "Sns": { - "SignatureVersion": "1", - "Timestamp": "1970-01-01T00:00:00.000Z", - "Signature": "EXAMPLE", - "SigningCertUrl": "EXAMPLE", - "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", - "Message": "message", - "MessageAttributes": { - "Test": { - "Type": "String", - "Value": "TestString" - }, - "TestBinary": { - "Type": "Binary", - "Value": "TestBinary" - } - }, - "Type": "Notification", - "UnsubscribeUrl": "EXAMPLE", - "TopicArn": "topic", - "Subject": "subject" - } - }] - } - - self.assertEquals(actual_event, expected_event) - - def test_api_event(self): - actual_event = generate_api_event("GET", "body of the request", "/path", "/path") - self.maxDiff = None - - expected_event = { - 'body': 'body of the request', - 'headers': { - 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', - 'Accept-Encoding': 'gzip, deflate, sdch', - 'Accept-Language': 'en-US,en;q=0.8', - 'Cache-Control': 'max-age=0', - 'CloudFront-Forwarded-Proto': 'https', - 'CloudFront-Is-Desktop-Viewer': 'true', - 'CloudFront-Is-Mobile-Viewer': 'false', - 'CloudFront-Is-SmartTV-Viewer': 'false', - 'CloudFront-Is-Tablet-Viewer': 'false', - 'CloudFront-Viewer-Country': 'US', - 'Host': '1234567890.execute-api.us-east-1.amazonaws.com', - 'Upgrade-Insecure-Requests': '1', - 'User-Agent': 'Custom User Agent String', - 'Via': '1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)', - 'X-Amz-Cf-Id': 'aaaaaaaaaae3VYQb9jd-nvCd-de396Uhbp027Y2JvkCPNLmGJHqlaA==', - 'X-Forwarded-For': '127.0.0.1, 127.0.0.2', - 'X-Forwarded-Port': '443', - 'X-Forwarded-Proto': 'https' - }, - 'httpMethod': 'GET', - 'isBase64Encoded': False, - 'path': '/path', - 'pathParameters': {'proxy': '/path'}, - 'queryStringParameters': {'foo': 'bar'}, - 'requestContext': { - 'accountId': "123456789012", - 'apiId': "1234567890", - 'extendedRequestId': None, - 'httpMethod': 'GET', - 'identity': { - 'accountId': None, - 'apiKey': None, - 'caller': None, - 'cognitoAuthenticationProvider': None, - 'cognitoAuthenticationType': None, - 'cognitoIdentityPoolId': None, - 'sourceIp': '127.0.0.1', - 'user': None, - 'userAgent': "Custom User Agent String", - 'userArn': None - }, - 'path': '/path', - 'requestId': "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", - 'resourceId': "123456", - 'resourcePath': '/path', - 'stage': 'prod' - }, - 'resource': '/path', - 'stageVariables': None - } - - self.assertEquals(actual_event, expected_event) - - def test_dynamodb_event(self): - actual_event = generate_dynamodb_event("us-east-1") - - expected_event = { - "Records": [ - { - "eventID": "1", - "eventVersion": "1.0", - "dynamodb": { - "Keys": { - "Id": { - "N": "101" - } - }, - "NewImage": { - "Message": { - "S": "New item!" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES", - "SequenceNumber": "111", - "SizeBytes": 26 - }, - "awsRegion": "us-east-1", - "eventName": "INSERT", - "eventSourceARN": "arn:aws:dynamodb:us-east-1:account-id:table/" - "ExampleTableWithStream/stream/2015-06-27T00:48:05.899", - "eventSource": "aws:dynamodb" - }, - { - "eventID": "2", - "eventVersion": "1.0", - "dynamodb": { - "OldImage": { - "Message": { - "S": "New item!" - }, - "Id": { - "N": "101" - } - }, - "SequenceNumber": "222", - "Keys": { - "Id": { - "N": "101" - } - }, - "SizeBytes": 59, - "NewImage": { - "Message": { - "S": "This item has changed" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES" - }, - "awsRegion": "us-east-1", - "eventName": "MODIFY", - "eventSourceARN": "arn:aws:dynamodb:us-east-1:account-id:table/" - "ExampleTableWithStream/stream/2015-06-27T00:48:05.899", - "eventSource": "aws:dynamodb" - }, - { - "eventID": "3", - "eventVersion": "1.0", - "dynamodb": { - "Keys": { - "Id": { - "N": "101" - } - }, - "SizeBytes": 38, - "SequenceNumber": "333", - "OldImage": { - "Message": { - "S": "This item has changed" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES" - }, - "awsRegion": "us-east-1", - "eventName": "REMOVE", - "eventSourceARN": "arn:aws:dynamodb:us-east-1:account-id:table/" - "ExampleTableWithStream/stream/2015-06-27T00:48:05.899", - "eventSource": "aws:dynamodb" - } - ] - } - - self.assertEquals(actual_event, expected_event) - - def test_schedule_event(self): - actual_event = generate_schedule_event("us-east-1") - - expected_event = { - "version": "0", - "account": "123456789012", - "region": "us-east-1", - "detail": {}, - "detail-type": "Scheduled Event", - "source": "aws.events", - "time": "1970-01-01T00:00:00Z", - "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c", - "resources": [ - "arn:aws:events:us-east-1:123456789012:rule/my-schedule" - ] - } - - self.assertEquals(actual_event, expected_event) - - def test_kinesis_event(self): - actual_event = generate_kinesis_event("us-east-1", "partition", "sequence", "this is data") - - expected_event = { - "Records": [{ - "eventID": "shardId-000000000000:sequence", - "eventVersion": "1.0", - "kinesis": { - "approximateArrivalTimestamp": 1428537600, - "partitionKey": "partition", - "data": "this is data", - "kinesisSchemaVersion": "1.0", - "sequenceNumber": "sequence" - }, - "invokeIdentityArn": "arn:aws:iam::EXAMPLE", - "eventName": "aws:kinesis:record", - "eventSourceARN": "arn:aws:kinesis:EXAMPLE", - "eventSource": "aws:kinesis", - "awsRegion": "us-east-1" - }] - } - - self.assertEquals(actual_event, expected_event)