diff --git a/go1.x/__init__.py b/go1.x/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/event-bridge-schema/README.md b/go1.x/event-bridge-schema/README.md deleted file mode 100644 index 252a3ea66..000000000 --- a/go1.x/event-bridge-schema/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Cookiecutter SAM for golang Lambda functions - -This is a dynamic [Cookiecutter](https://github.com/audreyr/cookiecutter) template to create a Serverless EventBridge Custom App based on Serverless Application Model (SAM) and Golang. - -It is important to note that you should not try to `git clone` this project but use `cookiecutter` CLI instead as ``{{cookiecutter.project_name}}`` will be rendered based on your input and therefore all variables and files will be rendered properly. - -This template creates a Serverless Application using a selected EventBridge Schema (selected during sam init interactive workflow), demonstrating the power of event-driven development with Amazon EventBridge. -## Requirements - -Install `cookiecutter` command line: - -**Pip users**: - -* `pip install cookiecutter` - -**Homebrew users**: - -* `brew install cookiecutter` - -**Windows or Pipenv users**: - -* `pipenv install cookiecutter` - -**NOTE**: [`Pipenv`](https://github.com/pypa/pipenv) is the new and recommended Python packaging tool that works across multiple platforms and makes Windows a first-class citizen. - -## Usage - -Access this template by running `sam init` and choosing it from the list of available templates - - -## Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) -* [Bruno Alla's Lambda function template](https://github.com/browniebroke/cookiecutter-lambda-function) - -## License - -This project is licensed under the terms of the [MIT License with no attribution](/LICENSE) \ No newline at end of file diff --git a/go1.x/event-bridge-schema/__init__.py b/go1.x/event-bridge-schema/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/event-bridge-schema/cookiecutter.json b/go1.x/event-bridge-schema/cookiecutter.json deleted file mode 100644 index bde167194..000000000 --- a/go1.x/event-bridge-schema/cookiecutter.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "project_name": "Your EventBridge Starter app", - "runtime": "go1.x", - "architectures": { - "value": [ "x86_64" ] - }, - "function_name": "HelloWorld", - "AWS_Schema_registry": "aws.events", - "AWS_Schema_name": "EC2InstanceStateChangeNotification", - "AWS_Schema_root": "aws.ec2.EC2InstanceStateChangeNotification", - "AWS_Schema_source": "aws.ec2", - "AWS_Schema_detail_type": "EC2 Instance State-change Notification", - "codegen_path": "{{ cookiecutter.project_name }}/{{ cookiecutter.function_name }}/{{ cookiecutter.AWS_Schema_root|lower|replace('.', '/') }}", - "codegen_package_name": "{{ cookiecutter.AWS_Schema_root.lower()[cookiecutter.AWS_Schema_root.rfind(\".\")+1:] }}", - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/go1.x/event-bridge-schema/requirements-dev.txt b/go1.x/event-bridge-schema/requirements-dev.txt deleted file mode 100644 index 151a0928c..000000000 --- a/go1.x/event-bridge-schema/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -cookiecutter==2.3.0 -flake8==3.5.0 -pytest==3.3.2 -pytest-cookies==0.3.0 diff --git a/go1.x/event-bridge-schema/tests/__init__.py b/go1.x/event-bridge-schema/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/Makefile b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/Makefile deleted file mode 100644 index cc2f72edf..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -.PHONY: build - -build: - go mod download github.com/aws/aws-lambda-go - sam build diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/README.md b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 0d4871409..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,126 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders. - -- {{cookiecutter.function_name}}/main.go - Code for the application's Lambda function. -- events - Invocation events that you can use to invoke the function. -- {{cookiecutter.function_name}}/main_tests.go - Unit tests for the application code. -- template.yaml - A template that defines the application's AWS resources. - - -The application uses several AWS resources, including Lambda functions and an EventBridge Rule trigger. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started. - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment. - -To use the SAM CLI, you need the following tools. - -* AWS CLI - [Install the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) and [configure it with your AWS credentials]. -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Golang - [Golang](https://golang.org) -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -The first command will build the source of your application. The second command will package and deploy your application to AWS, with a series of prompts: - -* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. -* **AWS Region**: The AWS region you want to deploy your app to. -* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes. -* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. -* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application. - -## Use the SAM CLI to build and test locally - -Build your application with the `sam build` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `go.mod`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the `events` folder in this project. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -{{ cookiecutter.project_name }}$ sam local invoke {{cookiecutter.function_name}} --event events/event.json -``` - -The SAM CLI reads the application template to determine the EventBridge rule pattern and the functions that they invoke as a target. The `Events` property on each function's definition includes the source and detail-type of the types of events that will invoke the function. - -```yaml - Events: - {{ cookiecutter.function_name }}: - Type: EventBridgeRule # More info about EventBridge Event Source: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#eventbridgerule - Properties: - Pattern: - source: - - {{ cookiecutter.AWS_Schema_source }} - detail-type: - - {{ cookiecutter.AWS_Schema_detail_type }} -``` - -## Add a resource to your application -The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in [the SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use standard [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html) resource types. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n {{cookiecutter.function_name}} --stack-name {{ cookiecutter.project_name }} --tail -``` - -You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -We use `testing` package that is built-in in Golang and you can simply run the following command to run the tests: - -```bash -go test -v ./{{cookiecutter.function_name}}/ -``` - -## Cleanup - -To delete the sample application that you created, use the SAM CLI. Assuming you used your project name for the stack name, you can run the following: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -See the [AWS SAM developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) for an introduction to SAM specification, the SAM CLI, and serverless application concepts. - -Next, you can use AWS Serverless Application Repository to deploy ready to use Apps that go beyond hello world samples and learn how authors developed their applications: [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) - - - - - diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/events/event.json b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index c33cb63e2..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "id":"7bf73129-1428-4cd3-a780-95db273d1602", - "detail-type":"{{ cookiecutter.AWS_Schema_detail_type }}", - "source":"{{ cookiecutter.AWS_Schema_source }}", - "account":"123456789012", - "time":"2015-11-11T21:29:54Z", - "region":"us-east-1", - "resources":[ - "arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1111" - ], - "detail":{ - "ADD-YOUR-FIELDS-HERE":"" - } -} \ No newline at end of file diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/go.mod b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/go.mod deleted file mode 100644 index 769735497..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.7.2 - gopkg.in/yaml.v3 v3.0.1 // indirect -) - -module {{ cookiecutter.project_name }} - -go 1.17 diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/go.sum b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/go.sum deleted file mode 100644 index 21837230f..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/go.sum +++ /dev/null @@ -1,14 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/template.yaml b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index c327b91c8..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,46 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - Sample SAM Template for {{ cookiecutter.project_name }} -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 20 - -Resources: - {{cookiecutter.function_name}}: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: {{cookiecutter.function_name}} - Handler: hello-world - Runtime: {{ cookiecutter.runtime }} - {%- if cookiecutter.architectures.value != [] %} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object - Variables: - PARAM1: VALUE - Events: - HelloWorld: - Type: EventBridgeRule # More info about EventBridge Event Source: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#eventbridgerule - Properties: - Pattern: - source: - - {{ cookiecutter.AWS_Schema_source }} - detail-type: - - {{ cookiecutter.AWS_Schema_detail_type }} - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - {{cookiecutter.function_name}}: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt {{cookiecutter.function_name}}.Arn - {{cookiecutter.function_name}}IamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt {{cookiecutter.function_name}}.Arn \ No newline at end of file diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/{{cookiecutter.function_name}}/main.go b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/{{cookiecutter.function_name}}/main.go deleted file mode 100644 index 8cc1e6573..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/{{cookiecutter.function_name}}/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "context" - "fmt" - "github.com/aws/aws-lambda-go/lambda" - "{{ cookiecutter.codegen_path }}" -) - -/* -Description: This lambda handler reads an {{ cookiecutter.AWS_Schema_detail_type }} from the inputted AWSEvent, then - updates the Detail Type (description of the type of AWS event). -Parameters: -- context: Object that provides information about the Lambda invocation, function, and execution environment. -- awsEvent: AWS EventBridge object that provides information such as the source, region, account the - event is associated with. -Output: Stream ([]byte) of the updated AWSEvent after function logic completed. -*/ -func handler(context context.Context, event {{ cookiecutter.codegen_package_name }}.AWSEvent) ([]byte , error) { - // Retrieve {{ cookiecutter.AWS_Schema_name }} detail from event - detail := event.Detail - fmt.Println("Reading {{ cookiecutter.AWS_Schema_name }}: ", detail) - - // Developers write your event-driven business logic code here! - // Make updates to the event payload - fmt.Println("{{ cookiecutter.function_name }} updating event of " + event.DetailType) - event.SetDetailType("{{ cookiecutter.function_name }} updated event of " + event.DetailType) - - // Return event as stream for further processing - return {{ cookiecutter.codegen_package_name }}.Marshal(event) - -} - -func main() { - lambda.Start(handler) -} diff --git a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/{{cookiecutter.function_name}}/main_test.go b/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/{{cookiecutter.function_name}}/main_test.go deleted file mode 100644 index 2af195864..000000000 --- a/go1.x/event-bridge-schema/{{cookiecutter.project_name}}/{{cookiecutter.function_name}}/main_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "fmt" - "github.com/stretchr/testify/assert" - "io" - "os" - "testing" - "{{ cookiecutter.codegen_path }}" -) - -var ( - PathToEventJsonFile = "../events/event.json" -) - -func TestHandler(t *testing.T) { - jsonFile, err := os.Open(PathToEventJsonFile) - if err != nil { - t.Fatal("Unable to open event.json") - } - - fmt.Println("Successfully Opened event.json") - - defer jsonFile.Close() - - jsonStream, _ := io.ReadAll(jsonFile) - - event, _ := {{ cookiecutter.codegen_package_name }}.UnmarshalEvent(jsonStream) - - t.Run("Successful Request", func(t *testing.T) { - responseStream, err := handler(nil, event) - if err != nil { - t.Fatal("Everything should be ok") - } - - responseEvent, _ := {{ cookiecutter.codegen_package_name }}.UnmarshalEvent(responseStream) - - assert.NotEmpty(t, responseEvent) - assert.Equal(t, responseEvent.DetailType, "{{cookiecutter.function_name}} updated event of {{ cookiecutter.AWS_Schema_detail_type }}") - }) -} diff --git a/go1.x/event-bridge/README.md b/go1.x/event-bridge/README.md deleted file mode 100644 index 9f7da5711..000000000 --- a/go1.x/event-bridge/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Cookiecutter SAM for Golang Lambda functions - -This is a static [Cookiecutter](https://github.com/audreyr/cookiecutter) template to create a Serverless EventBridge Hello World App based on Serverless Application Model (SAM) and Golang. - -It is important to note that you should not try to `git clone` this project but use `cookiecutter` CLI instead as ``{{cookiecutter.project_name}}`` will be rendered based on your input and therefore all variables and files will be rendered properly. - -This template creates a Serverless Application that reacts to EC2 Instance State change events, demonstrating the power of event-driven development with Amazon EventBridge. -## Requirements - -Install `cookiecutter` command line: - -**Pip users**: - -* `pip install cookiecutter` - -**Homebrew users**: - -* `brew install cookiecutter` - -**Windows or Pipenv users**: - -* `pipenv install cookiecutter` - -**NOTE**: [`Pipenv`](https://github.com/pypa/pipenv) is the new and recommended Python packaging tool that works across multiple platforms and makes Windows a first-class citizen. - -## Usage - -Access this template by running `sam init` and choosing it from the list of available templates - - -## Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) -* [Bruno Alla's Lambda function template](https://github.com/browniebroke/cookiecutter-lambda-function) - -## License - -This project is licensed under the terms of the [MIT License with no attribution](/LICENSE) \ No newline at end of file diff --git a/go1.x/event-bridge/__init__.py b/go1.x/event-bridge/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/event-bridge/cookiecutter.json b/go1.x/event-bridge/cookiecutter.json deleted file mode 100644 index 10cd76e23..000000000 --- a/go1.x/event-bridge/cookiecutter.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "project_name": "Your EventBridge Starter App", - "runtime": "go1.x", - "architectures": { - "value": [ "x86_64" ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/go1.x/event-bridge/requirements-dev.txt b/go1.x/event-bridge/requirements-dev.txt deleted file mode 100644 index 151a0928c..000000000 --- a/go1.x/event-bridge/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -cookiecutter==2.3.0 -flake8==3.5.0 -pytest==3.3.2 -pytest-cookies==0.3.0 diff --git a/go1.x/event-bridge/tests/__init__.py b/go1.x/event-bridge/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/Makefile b/go1.x/event-bridge/{{cookiecutter.project_name}}/Makefile deleted file mode 100644 index cc2f72edf..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -.PHONY: build - -build: - go mod download github.com/aws/aws-lambda-go - sam build diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/README.md b/go1.x/event-bridge/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 7eff31c8f..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,128 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders. - -- hello-world/main.go - Code for the application's Lambda function. -- events - Invocation events that you can use to invoke the function. -- hello-world/main_tests.go - Unit tests for the application code. -- template.yaml - A template that defines the application's AWS resources. - -This application reacts to EC2 Instance State change events, demonstrating the power of event-driven development with Amazon EventBridge. - -The application uses several AWS resources, including Lambda functions and an EventBridge Rule trigger. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. -The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started. - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment. - -To use the SAM CLI, you need the following tools. - -* AWS CLI - [Install the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) and [configure it with your AWS credentials]. -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* Golang - [Golang](https://golang.org) -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -The first command will build the source of your application. The second command will package and deploy your application to AWS, with a series of prompts: - -* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. -* **AWS Region**: The AWS region you want to deploy your app to. -* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes. -* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. -* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application. - -## Use the SAM CLI to build and test locally - -Build your application with the `sam build` command. - -```bash -{{ cookiecutter.project_name }}$ sam build -``` - -The SAM CLI installs dependencies defined in `go.mod`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the `events` folder in this project. - -Run functions locally and invoke them with the `sam local invoke` command. - -```bash -{{ cookiecutter.project_name }}$ sam local invoke HelloWorldFunction --event events/event.json -``` - -The SAM CLI reads the application template to determine the EventBridge rule pattern and the functions that they invoke as a target. The `Events` property on each function's definition includes the source and detail-type of the types of events that will invoke the function. - -```yaml - Events: - HelloWorld: - Type: EventBridgeRule # More info about EventBridge Event Source: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#eventbridgerule - Properties: - Pattern: - source: - - aws.ec2 - detail-type: - - EC2 Instance State-change Notification -``` - -## Add a resource to your application -The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in [the SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use standard [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html) resource types. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n HelloWorldFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -We use `testing` package that is built-in in Golang and you can simply run the following commands to run the tests: - -```bash -go test -v ./hello-world/ -``` - - -## Cleanup - -To delete the sample application that you created, use the SAM CLI. Assuming you used your project name for the stack name, you can run the following: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -See the [AWS SAM developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) for an introduction to SAM specification, the SAM CLI, and serverless application concepts. - -Next, you can use AWS Serverless Application Repository to deploy ready to use Apps that go beyond hello world samples and learn how authors developed their applications: [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) - - - - - diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/events/event.json b/go1.x/event-bridge/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index 1caf41d38..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "id":"7bf73129-1428-4cd3-a780-95db273d1602", - "detail-type":"EC2 Instance State-change Notification", - "source":"aws.ec2", - "account":"123456789012", - "time":"2015-11-11T21:29:54Z", - "region":"us-east-1", - "resources":[ - "arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1111" - ], - "detail":{ - "instance-id":"i-abcd1111", - "state":"pending" - } -} \ No newline at end of file diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/go.mod b/go1.x/event-bridge/{{cookiecutter.project_name}}/go.mod deleted file mode 100644 index 769735497..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.7.2 - gopkg.in/yaml.v3 v3.0.1 // indirect -) - -module {{ cookiecutter.project_name }} - -go 1.17 diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/go.sum b/go1.x/event-bridge/{{cookiecutter.project_name}}/go.sum deleted file mode 100644 index 21837230f..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/go.sum +++ /dev/null @@ -1,14 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/main.go b/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/main.go deleted file mode 100644 index e29606d0f..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "context" - "fmt" - "github.com/aws/aws-lambda-go/lambda" - "{{ cookiecutter.project_name }}/hello-world/model/aws/ec2" - "{{ cookiecutter.project_name }}/hello-world/model/aws/ec2/marshaller" -) - -/* -Description: This lambda handler reads an EC2 Instance Change Notification from the inputted AWSEvent, then updates the - Detail Type (description of the type of AWS event). -Parameters: -- context: Object that provides information about the Lambda invocation, function, and execution environment. -- awsEvent: AWS EventBridge object that provides information such as the source, region, account the - event is associated with. -Output: Stream ([]byte) of the updated AWSEvent after function logic completed. -*/ -func handler(context context.Context, awsEvent ec2.AWSEvent) ([]byte , error) { - // Retrieve the ec2 notification from the event - ec2InstanceStateChangeNotification := awsEvent.Detail - - // Developers write your event-driven business logic code here! - fmt.Println("Instance " + ec2InstanceStateChangeNotification.InstanceId + " transitioned to " + ec2InstanceStateChangeNotification.State) - - // Make updates to the event payload - awsEvent.SetDetailType("HelloWorldFunction updated event of " + awsEvent.DetailType) - - // Return event as stream for further processing - return marshaller.Marshal(awsEvent) - -} - -func main() { - lambda.Start(handler) -} diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/main_test.go b/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/main_test.go deleted file mode 100644 index 719c64eb2..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/main_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "fmt" - "github.com/stretchr/testify/assert" - "io" - "os" - "testing" - "{{ cookiecutter.project_name }}/hello-world/model/aws/ec2/marshaller" -) - -var ( - PathToEventJsonFile = "../events/event.json" -) - -func TestHandler(t *testing.T) { - jsonFile, err := os.Open(PathToEventJsonFile) - if err != nil { - t.Fatal("Unable to open event.json") - } - - fmt.Println("Successfully Opened event.json") - - defer jsonFile.Close() - - jsonStream, _ := io.ReadAll(jsonFile) - - awsEvent, _ := marshaller.UnmarshalEvent(jsonStream) - - t.Run("Successful Request", func(t *testing.T) { - responseStream, err := handler(nil, awsEvent) - if err != nil { - t.Fatal("Everything should be ok") - } - - responseEvent, _ := marshaller.UnmarshalEvent(responseStream) - responseEc2Notification := responseEvent.Detail - - assert.NotEmpty(t, responseEvent) - assert.Equal(t, responseEvent.DetailType, "HelloWorldFunction updated event of EC2 Instance State-change Notification") - assert.Equal(t, responseEc2Notification.InstanceId, "i-abcd1111") - }) -} diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/aws_event.go b/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/aws_event.go deleted file mode 100644 index 49640a849..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/aws_event.go +++ /dev/null @@ -1,53 +0,0 @@ -package ec2 - -import ( - "time" -) - -type AWSEvent struct { - Detail EC2InstanceStateChangeNotification `json:"detail"` - DetailType string `json:"detail-type"` - Resources []string `json:"resources"` - Id string `json:"id"` - Source string `json:"source"` - Time time.Time `json:"time"` - Region string `json:"region"` - Version string `json:"version"` - Account string `json:"account"` -} - -func (a *AWSEvent) SetDetail(detail EC2InstanceStateChangeNotification) { - a.Detail = detail -} - -func (a *AWSEvent) SetDetailType(detailType string) { - a.DetailType = detailType -} - -func (a *AWSEvent) SetResources(resources []string) { - a.Resources = resources -} - -func (a *AWSEvent) SetId(id string) { - a.Id = id -} - -func (a *AWSEvent) SetSource(source string) { - a.Source = source -} - -func (a *AWSEvent) SetTime(time time.Time) { - a.Time = time -} - -func (a *AWSEvent) SetRegion(region string) { - a.Region = region -} - -func (a *AWSEvent) SetVersion(version string) { - a.Version = version -} - -func (a *AWSEvent) SetAccount(account string) { - a.Account = account -} diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/ec2_instance_state_change_notification.go b/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/ec2_instance_state_change_notification.go deleted file mode 100644 index 178dd4d0a..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/ec2_instance_state_change_notification.go +++ /dev/null @@ -1,14 +0,0 @@ -package ec2 - -type EC2InstanceStateChangeNotification struct { - InstanceId string `json:"instance-id"` - State string `json:"state"` -} - -func (e *EC2InstanceStateChangeNotification) SetInstanceId(instanceId string) { - e.InstanceId = instanceId -} - -func (e *EC2InstanceStateChangeNotification) SetState(state string) { - e.State = state -} diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/marshaller/marshaller.go b/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/marshaller/marshaller.go deleted file mode 100644 index 3850abbfb..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/hello-world/model/aws/ec2/marshaller/marshaller.go +++ /dev/null @@ -1,35 +0,0 @@ -package marshaller - -import ( - "encoding/json" - "{{ cookiecutter.project_name }}/hello-world/model/aws/ec2" -) - -func Marshal(inputEvent interface{}) ([]byte, error) { - outputStream, err := json.Marshal(inputEvent) - if err != nil { - return nil, err - } - - return outputStream, nil -} - -func Unmarshal(inputStream []byte) (map[string]interface{}, error) { - var outputEvent map[string]interface{} - err := json.Unmarshal(inputStream, &outputEvent) - if err != nil { - return nil, err - } - - return outputEvent, nil -} - -func UnmarshalEvent(inputStream []byte) (ec2.AWSEvent, error) { - var outputEvent ec2.AWSEvent - err := json.Unmarshal(inputStream, &outputEvent) - if err != nil { - return ec2.AWSEvent{}, err - } - - return outputEvent, nil -} diff --git a/go1.x/event-bridge/{{cookiecutter.project_name}}/template.yaml b/go1.x/event-bridge/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index f51e5795f..000000000 --- a/go1.x/event-bridge/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,47 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - Sample SAM Template for {{ cookiecutter.project_name }} -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 20 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: hello-world/ - Handler: hello-world - Runtime: go1.x - {%- if cookiecutter.architectures.value != [] %} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object - Variables: - PARAM1: VALUE - Events: - HelloWorld: - Type: EventBridgeRule # More info about EventBridge Event Source: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#eventbridgerule - Properties: - Pattern: - source: - - aws.ec2 - detail-type: - - EC2 Instance State-change Notification - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldFunction: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn \ No newline at end of file diff --git a/go1.x/hello-img/README.md b/go1.x/hello-img/README.md deleted file mode 100644 index d6af33a92..000000000 --- a/go1.x/hello-img/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Cookiecutter SAM for golang Lambda functions - -This is a [Cookiecutter](https://github.com/audreyr/cookiecutter) template to create a Serverless App based on Serverless Application Model (SAM). - -It is important to note that you should not try to `git clone` this project but use `cookiecutter` CLI instead as ``\\{\\{cookiecutter.project_slug\\}\\}`` will be rendered based on your input and therefore all variables and files will be rendered properly. - -## Requirements - -Install `cookiecutter` command line: - -**Pip users**: - -* `pip install cookiecutter` - -**Homebrew users**: - -* `brew install cookiecutter` - -**Windows or Pipenv users**: - -* `pipenv install cookiecutter` - -**NOTE**: [`Pipenv`](https://github.com/pypa/pipenv) is the new and recommended Python packaging tool that works across multiple platforms and makes Windows a first-class citizen. - -## Usage - -Generate a new SAM based Serverless App: `cookiecutter gh:aws-samples/cookiecutter-aws-sam-golang`. - -You'll be prompted a few questions to help this cookiecutter template to scaffold this project and after its completed you should see a new folder at your current path with the name of the project you gave as input. - -**NOTE**: After you understand how cookiecutter works (cookiecutter.json, mainly), you can fork this repo and apply your own mechanisms to accelerate your development process and this can be followed for any programming language and OS. - -## Options - -Option | Description -------------------------------------------------- | --------------------------------------------------------------------------------- -`include_apigw` | Includes sample code for API Gateway Proxy integration for Lambda and a Catch All method in SAM as a starting point -`include_xray` | Includes both sample code for getting started with AWS X-Ray and adds necessary permission and `Tracing` to your function -`include_safe_deployment` | Sends by default 10% of traffic for every 1 minute to a newly deployed function using [CodeDeploy + SAM integration](https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst) - Linear10PercentEvery1Minute -`include_experimental_make` | Includes a `Makefile` for advanced users to automate packaging, build, tests and SAM Local - Only works on OSX/Linux at the moment - -## Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) -* [Bruno Alla's Lambda function template](https://github.com/browniebroke/cookiecutter-lambda-function) - -## License - -This project is licensed under the terms of the [MIT License with no attribution](/LICENSE) \ No newline at end of file diff --git a/go1.x/hello-img/__init__.py b/go1.x/hello-img/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/hello-img/cookiecutter.json b/go1.x/hello-img/cookiecutter.json deleted file mode 100644 index 60a2a90c7..000000000 --- a/go1.x/hello-img/cookiecutter.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "go1.x", - "architectures": { - "value": [ "x86_64" ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/go1.x/hello-img/requirements-dev.txt b/go1.x/hello-img/requirements-dev.txt deleted file mode 100644 index 151a0928c..000000000 --- a/go1.x/hello-img/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -cookiecutter==2.3.0 -flake8==3.5.0 -pytest==3.3.2 -pytest-cookies==0.3.0 diff --git a/go1.x/hello-img/tests/__init__.py b/go1.x/hello-img/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/hello-img/tests/test_bake_project.py b/go1.x/hello-img/tests/test_bake_project.py deleted file mode 100644 index ab81949ba..000000000 --- a/go1.x/hello-img/tests/test_bake_project.py +++ /dev/null @@ -1,78 +0,0 @@ -from contextlib import contextmanager - -import os - - -@contextmanager -def inside_dir(dirpath): - """ - Execute code from inside the given directory - :param dirpath: String, path of the directory the command is being run. - """ - old_path = os.getcwd() - try: - os.chdir(dirpath) - yield - finally: - os.chdir(old_path) - - -def test_project_tree(cookies): - result = cookies.bake(extra_context={"project_name": "test_project"}) - assert result.exit_code == 0 - assert result.exception is None - assert result.project.basename == "test_project" - - assert result.project.isdir() - assert result.project.join("README.md").isfile() - assert result.project.join("template.yaml").isfile() - assert result.project.join("hello-world").isdir() - assert result.project.join("hello-world", "main.go").isfile() - assert result.project.join("hello-world", "main_test.go").isfile() - - -def test_app_content(cookies): - result = cookies.bake(extra_context={"project_name": "test_project"}) - app_file = result.project.join("hello-world", "main.go") - app_content = app_file.readlines() - app_content = "".join(app_content) - - contents = ( - "github.com/aws/aws-lambda-go/events", - "sourceIP := request.RequestContext.Identity.SourceIP", - "lambda.Start(handler)" - ) - - for content in contents: - assert content in app_content - - -def test_app_test_content(cookies): - result = cookies.bake(extra_context={"project_name": "test_project"}) - app_file = result.project.join("hello-world", "main_test.go") - app_content = app_file.readlines() - app_content = "".join(app_content) - - contents = ( - "func TestHandler(t *testing.T)", - "SourceIP: \"127.0.0.1\"", - "response, err := handler(testCase.request)" - ) - - for content in contents: - assert content in app_content - - -def test_app_template_content(cookies): - result = cookies.bake(extra_context={"project_name": "test_project"}) - app_file = result.project.join("template.yaml") - app_content = app_file.readlines() - app_content = "".join(app_content) - - contents = ( - "Runtime: go1.x", - "HelloWorldFunction", - ) - - for content in contents: - assert content in app_content diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/README.md b/go1.x/hello-img/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 3a5eca541..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,137 +0,0 @@ -# {{ cookiecutter.project_name }} - -This is a sample template for {{ cookiecutter.project_name }} - Below is a brief explanation of what we have generated for you: - -```bash -. -├── README.md <-- This instructions file -├── hello-world <-- Source code for a lambda function -│ ├── main.go <-- Lambda function code -│ └── main_test.go <-- Unit tests -│ └── Dockerfile <-- Dockerfile -└── template.yaml -``` - -## Requirements - -* AWS CLI already configured with Administrator permission -* [Docker installed](https://www.docker.com/community-edition) -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - -You may need the following for local testing. -* [Golang](https://golang.org) - -## Setup process - -### Installing dependencies & building the target - -In this example we use the built-in `sam build` to build a docker image from a Dockerfile and then copy the source of your application inside the Docker image. -Read more about [SAM Build here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html) - -### Local development - -**Invoking function locally through local API Gateway** - -```bash -sam local start-api -``` - -If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:3000/hello` - -**SAM CLI** is used to emulate both Lambda and API Gateway locally and uses our `template.yaml` to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The following excerpt is what the CLI will read in order to initialize an API and its routes: - -```yaml -... -Events: - HelloWorld: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: get -``` - -## Packaging and deployment - -AWS Lambda Golang runtime requires a flat folder with the executable generated on build step. SAM will use `CodeUri` property to know where to look up for the application: - -```yaml -... - FirstFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: hello_world/ - ... -``` - -To deploy your application for the first time, run the following in your shell: - -```bash -sam deploy --guided -``` - -The command will package and deploy your application to AWS, with a series of prompts: - -* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. -* **AWS Region**: The AWS region you want to deploy your app to. -* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes. -* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. -* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application. - -You can find your API Gateway Endpoint URL in the output values displayed after deployment. - -### Testing - -We use `testing` package that is built-in in Golang and you can simply run the following command to run our tests locally: - -```shell -cd ./hello-world/ -go test -v . -``` -# Appendix - -### Golang installation - -Please ensure Go 1.x (where 'x' is the latest version) is installed as per the instructions on the official golang website: https://golang.org/doc/install - -A quickstart way would be to use Homebrew, chocolatey or your linux package manager. - -#### Homebrew (Mac) - -Issue the following command from the terminal: - -```shell -brew install golang -``` - -If it's already installed, run the following command to ensure it's the latest version: - -```shell -brew update -brew upgrade golang -``` - -#### Chocolatey (Windows) - -Issue the following command from the powershell: - -```shell -choco install golang -``` - -If it's already installed, run the following command to ensure it's the latest version: - -```shell -choco upgrade golang -``` - -## Bringing to the next level - -Here are a few ideas that you can use to get more acquainted as to how this overall process works: - -* Create an additional API resource (e.g. /hello/{proxy+}) and return the name requested through this new path -* Update unit test to capture that -* Package & Deploy - -Next, you can use the following resources to know more about beyond hello world samples and how others structure their Serverless applications: - -* [AWS Serverless Application Repository](https://aws.amazon.com/serverless/serverlessrepo/) diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile b/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile deleted file mode 100644 index 352d84ecd..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM public.ecr.aws/bitnami/golang:1.19 as build-image - -WORKDIR /go/src -COPY go.mod go.sum main.go ./ - -RUN go build -o ../bin - -FROM public.ecr.aws/lambda/go:1 - -COPY --from=build-image /go/bin/ /var/task/ - -# Command can be overwritten by providing a different command in the template directly. -CMD ["hello-world"] diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/go.mod b/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/go.mod deleted file mode 100644 index 32da1ab76..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.8 - -module hello-world - -go 1.16 diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/go.sum b/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/go.sum deleted file mode 100644 index d1ee29f48..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/go.sum +++ /dev/null @@ -1,13 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/main.go b/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/main.go deleted file mode 100644 index 55d93a3da..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/aws/aws-lambda-go/events" - "github.com/aws/aws-lambda-go/lambda" -) - -func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { - var greeting string - sourceIP := request.RequestContext.Identity.SourceIP - - if sourceIP == "" { - greeting = "Hello, world!\n" - } else { - greeting = fmt.Sprintf("Hello, %s!\n", sourceIP) - } - - return events.APIGatewayProxyResponse{ - Body: greeting, - StatusCode: 200, - }, nil -} - -func main() { - lambda.Start(handler) -} diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/main_test.go b/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/main_test.go deleted file mode 100644 index b69105174..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/hello-world/main_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "testing" - - "github.com/aws/aws-lambda-go/events" -) - -func TestHandler(t *testing.T) { - testCases := []struct { - name string - request events.APIGatewayProxyRequest - expectedBody string - expectedError error - }{ - { - // mock a request with an empty SourceIP - name: "empty IP", - request: events.APIGatewayProxyRequest{ - RequestContext: events.APIGatewayProxyRequestContext{ - Identity: events.APIGatewayRequestIdentity{ - SourceIP: "", - }, - }, - }, - expectedBody: "Hello, world!\n", - expectedError: nil, - }, - { - // mock a request with a localhost SourceIP - name: "localhost IP", - request: events.APIGatewayProxyRequest{ - RequestContext: events.APIGatewayProxyRequestContext{ - Identity: events.APIGatewayRequestIdentity{ - SourceIP: "127.0.0.1", - }, - }, - }, - expectedBody: "Hello, 127.0.0.1!\n", - expectedError: nil, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T) { - response, err := handler(testCase.request) - if err != testCase.expectedError { - t.Errorf("Expected error %v, but got %v", testCase.expectedError, err) - } - - if response.Body != testCase.expectedBody { - t.Errorf("Expected response %v, but got %v", testCase.expectedBody, response.Body) - } - - if response.StatusCode != 200 { - t.Errorf("Expected status code 200, but got %v", response.StatusCode) - } - }) - } -} diff --git a/go1.x/hello-img/{{cookiecutter.project_name}}/template.yaml b/go1.x/hello-img/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 1081c1532..000000000 --- a/go1.x/hello-img/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,51 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 5 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - PackageType: Image - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Events: - CatchAll: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: GET - Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object - Variables: - PARAM1: VALUE - Metadata: - DockerTag: {{cookiecutter.runtime}}-v1 - DockerContext: ./hello-world - Dockerfile: Dockerfile - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldAPI: - Description: "API Gateway endpoint URL for Prod environment for First Function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "First Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/go1.x/hello/README.md b/go1.x/hello/README.md deleted file mode 100644 index d6af33a92..000000000 --- a/go1.x/hello/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Cookiecutter SAM for golang Lambda functions - -This is a [Cookiecutter](https://github.com/audreyr/cookiecutter) template to create a Serverless App based on Serverless Application Model (SAM). - -It is important to note that you should not try to `git clone` this project but use `cookiecutter` CLI instead as ``\\{\\{cookiecutter.project_slug\\}\\}`` will be rendered based on your input and therefore all variables and files will be rendered properly. - -## Requirements - -Install `cookiecutter` command line: - -**Pip users**: - -* `pip install cookiecutter` - -**Homebrew users**: - -* `brew install cookiecutter` - -**Windows or Pipenv users**: - -* `pipenv install cookiecutter` - -**NOTE**: [`Pipenv`](https://github.com/pypa/pipenv) is the new and recommended Python packaging tool that works across multiple platforms and makes Windows a first-class citizen. - -## Usage - -Generate a new SAM based Serverless App: `cookiecutter gh:aws-samples/cookiecutter-aws-sam-golang`. - -You'll be prompted a few questions to help this cookiecutter template to scaffold this project and after its completed you should see a new folder at your current path with the name of the project you gave as input. - -**NOTE**: After you understand how cookiecutter works (cookiecutter.json, mainly), you can fork this repo and apply your own mechanisms to accelerate your development process and this can be followed for any programming language and OS. - -## Options - -Option | Description -------------------------------------------------- | --------------------------------------------------------------------------------- -`include_apigw` | Includes sample code for API Gateway Proxy integration for Lambda and a Catch All method in SAM as a starting point -`include_xray` | Includes both sample code for getting started with AWS X-Ray and adds necessary permission and `Tracing` to your function -`include_safe_deployment` | Sends by default 10% of traffic for every 1 minute to a newly deployed function using [CodeDeploy + SAM integration](https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst) - Linear10PercentEvery1Minute -`include_experimental_make` | Includes a `Makefile` for advanced users to automate packaging, build, tests and SAM Local - Only works on OSX/Linux at the moment - -## Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) -* [Bruno Alla's Lambda function template](https://github.com/browniebroke/cookiecutter-lambda-function) - -## License - -This project is licensed under the terms of the [MIT License with no attribution](/LICENSE) \ No newline at end of file diff --git a/go1.x/hello/__init__.py b/go1.x/hello/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/hello/cookiecutter.json b/go1.x/hello/cookiecutter.json deleted file mode 100644 index 60a2a90c7..000000000 --- a/go1.x/hello/cookiecutter.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "go1.x", - "architectures": { - "value": [ "x86_64" ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/go1.x/hello/requirements-dev.txt b/go1.x/hello/requirements-dev.txt deleted file mode 100644 index 151a0928c..000000000 --- a/go1.x/hello/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -cookiecutter==2.3.0 -flake8==3.5.0 -pytest==3.3.2 -pytest-cookies==0.3.0 diff --git a/go1.x/hello/tests/__init__.py b/go1.x/hello/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/hello/tests/test_bake_project.py b/go1.x/hello/tests/test_bake_project.py deleted file mode 100644 index d19187d2e..000000000 --- a/go1.x/hello/tests/test_bake_project.py +++ /dev/null @@ -1,78 +0,0 @@ -from contextlib import contextmanager - -import os - - -@contextmanager -def inside_dir(dirpath): - """ - Execute code from inside the given directory - :param dirpath: String, path of the directory the command is being run. - """ - old_path = os.getcwd() - try: - os.chdir(dirpath) - yield - finally: - os.chdir(old_path) - - -def test_project_tree(cookies): - result = cookies.bake(extra_context={'project_name': 'test_project'}) - assert result.exit_code == 0 - assert result.exception is None - assert result.project.basename == 'test_project' - - assert result.project.isdir() - assert result.project.join('README.md').isfile() - assert result.project.join('template.yaml').isfile() - assert result.project.join('hello-world').isdir() - assert result.project.join('hello-world', 'main.go').isfile() - assert result.project.join('hello-world', 'main_test.go').isfile() - - -def test_app_content(cookies): - result = cookies.bake(extra_context={'project_name': 'test_project'}) - app_file = result.project.join('hello-world', 'main.go') - app_content = app_file.readlines() - app_content = ''.join(app_content) - - contents = ( - "github.com/aws/aws-lambda-go/events", - "sourceIP := request.RequestContext.Identity.SourceIP", - "lambda.Start(handler)" - ) - - for content in contents: - assert content in app_content - - -def test_app_test_content(cookies): - result = cookies.bake(extra_context={'project_name': 'test_project'}) - app_file = result.project.join('hello-world', 'main_test.go') - app_content = app_file.readlines() - app_content = ''.join(app_content) - - contents = ( - "func TestHandler(t *testing.T)", - "SourceIP: \"127.0.0.1\"", - "response, err := handler(testCase.request)" - ) - - for content in contents: - assert content in app_content - - -def test_app_template_content(cookies): - result = cookies.bake(extra_context={'project_name': 'test_project'}) - app_file = result.project.join('template.yaml') - app_content = app_file.readlines() - app_content = ''.join(app_content) - - contents = ( - "Runtime: go1.x", - "HelloWorldFunction", - ) - - for content in contents: - assert content in app_content diff --git a/go1.x/hello/{{cookiecutter.project_name}}/Makefile b/go1.x/hello/{{cookiecutter.project_name}}/Makefile deleted file mode 100644 index a6699b6e8..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -.PHONY: build - -build: - sam build diff --git a/go1.x/hello/{{cookiecutter.project_name}}/README.md b/go1.x/hello/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 488bec19b..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,141 +0,0 @@ -# {{ cookiecutter.project_name }} - -This is a sample template for {{ cookiecutter.project_name }} - Below is a brief explanation of what we have generated for you: - -```bash -. -├── Makefile <-- Make to automate build -├── README.md <-- This instructions file -├── hello-world <-- Source code for a lambda function -│ ├── main.go <-- Lambda function code -│ └── main_test.go <-- Unit tests -└── template.yaml -``` - -## Requirements - -* AWS CLI already configured with Administrator permission -* [Docker installed](https://www.docker.com/community-edition) -* [Golang](https://golang.org) -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - -## Setup process - -### Installing dependencies & building the target - -In this example we use the built-in `sam build` to automatically download all the dependencies and package our build target. -Read more about [SAM Build here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html) - -The `sam build` command is wrapped inside of the `Makefile`. To execute this simply run - -```shell -make -``` - -### Local development - -**Invoking function locally through local API Gateway** - -```bash -sam local start-api -``` - -If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:3000/hello` - -**SAM CLI** is used to emulate both Lambda and API Gateway locally and uses our `template.yaml` to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The following excerpt is what the CLI will read in order to initialize an API and its routes: - -```yaml -... -Events: - HelloWorld: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: get -``` - -## Packaging and deployment - -AWS Lambda Golang runtime requires a flat folder with the executable generated on build step. SAM will use `CodeUri` property to know where to look up for the application: - -```yaml -... - FirstFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: hello_world/ - ... -``` - -To deploy your application for the first time, run the following in your shell: - -```bash -sam deploy --guided -``` - -The command will package and deploy your application to AWS, with a series of prompts: - -* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. -* **AWS Region**: The AWS region you want to deploy your app to. -* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes. -* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. -* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application. - -You can find your API Gateway Endpoint URL in the output values displayed after deployment. - -### Testing - -We use `testing` package that is built-in in Golang and you can simply run the following command to run our tests: - -```shell -cd ./hello-world/ -go test -v . -``` -# Appendix - -### Golang installation - -Please ensure Go 1.x (where 'x' is the latest version) is installed as per the instructions on the official golang website: https://golang.org/doc/install - -A quickstart way would be to use Homebrew, chocolatey or your linux package manager. - -#### Homebrew (Mac) - -Issue the following command from the terminal: - -```shell -brew install golang -``` - -If it's already installed, run the following command to ensure it's the latest version: - -```shell -brew update -brew upgrade golang -``` - -#### Chocolatey (Windows) - -Issue the following command from the powershell: - -```shell -choco install golang -``` - -If it's already installed, run the following command to ensure it's the latest version: - -```shell -choco upgrade golang -``` - -## Bringing to the next level - -Here are a few ideas that you can use to get more acquainted as to how this overall process works: - -* Create an additional API resource (e.g. /hello/{proxy+}) and return the name requested through this new path -* Update unit test to capture that -* Package & Deploy - -Next, you can use the following resources to know more about beyond hello world samples and how others structure their Serverless applications: - -* [AWS Serverless Application Repository](https://aws.amazon.com/serverless/serverlessrepo/) diff --git a/go1.x/hello/{{cookiecutter.project_name}}/events/event.json b/go1.x/hello/{{cookiecutter.project_name}}/events/event.json deleted file mode 100644 index a429ac5e5..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/events/event.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "body": "{\"message\": \"hello world\"}", - "resource": "/hello", - "path": "/hello", - "httpMethod": "GET", - "isBase64Encoded": false, - "queryStringParameters": { - "foo": "bar" - }, - "pathParameters": { - "proxy": "/path/to/resource" - }, - "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": "123456789012", - "resourceId": "123456", - "stage": "prod", - "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": "/prod/hello", - "resourcePath": "/hello", - "httpMethod": "POST", - "apiId": "1234567890", - "protocol": "HTTP/1.1" - } - } - \ No newline at end of file diff --git a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/go.mod b/go1.x/hello/{{cookiecutter.project_name}}/hello-world/go.mod deleted file mode 100644 index 32da1ab76..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.8 - -module hello-world - -go 1.16 diff --git a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/go.sum b/go1.x/hello/{{cookiecutter.project_name}}/hello-world/go.sum deleted file mode 100644 index d1ee29f48..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/go.sum +++ /dev/null @@ -1,13 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/main.go b/go1.x/hello/{{cookiecutter.project_name}}/hello-world/main.go deleted file mode 100644 index 55d93a3da..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/aws/aws-lambda-go/events" - "github.com/aws/aws-lambda-go/lambda" -) - -func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { - var greeting string - sourceIP := request.RequestContext.Identity.SourceIP - - if sourceIP == "" { - greeting = "Hello, world!\n" - } else { - greeting = fmt.Sprintf("Hello, %s!\n", sourceIP) - } - - return events.APIGatewayProxyResponse{ - Body: greeting, - StatusCode: 200, - }, nil -} - -func main() { - lambda.Start(handler) -} diff --git a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/main_test.go b/go1.x/hello/{{cookiecutter.project_name}}/hello-world/main_test.go deleted file mode 100644 index b69105174..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/hello-world/main_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "testing" - - "github.com/aws/aws-lambda-go/events" -) - -func TestHandler(t *testing.T) { - testCases := []struct { - name string - request events.APIGatewayProxyRequest - expectedBody string - expectedError error - }{ - { - // mock a request with an empty SourceIP - name: "empty IP", - request: events.APIGatewayProxyRequest{ - RequestContext: events.APIGatewayProxyRequestContext{ - Identity: events.APIGatewayRequestIdentity{ - SourceIP: "", - }, - }, - }, - expectedBody: "Hello, world!\n", - expectedError: nil, - }, - { - // mock a request with a localhost SourceIP - name: "localhost IP", - request: events.APIGatewayProxyRequest{ - RequestContext: events.APIGatewayProxyRequestContext{ - Identity: events.APIGatewayRequestIdentity{ - SourceIP: "127.0.0.1", - }, - }, - }, - expectedBody: "Hello, 127.0.0.1!\n", - expectedError: nil, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T) { - response, err := handler(testCase.request) - if err != testCase.expectedError { - t.Errorf("Expected error %v, but got %v", testCase.expectedError, err) - } - - if response.Body != testCase.expectedBody { - t.Errorf("Expected response %v, but got %v", testCase.expectedBody, response.Body) - } - - if response.StatusCode != 200 { - t.Errorf("Expected status code 200, but got %v", response.StatusCode) - } - }) - } -} diff --git a/go1.x/hello/{{cookiecutter.project_name}}/template.yaml b/go1.x/hello/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 7d94909f2..000000000 --- a/go1.x/hello/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,49 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst -Globals: - Function: - Timeout: 10 - MemorySize: 128 - -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Properties: - CodeUri: hello-world/ - Handler: hello-world - Runtime: go1.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - Events: - CatchAll: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: GET - Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object - Variables: - PARAM1: VALUE - -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldAPI: - Description: "API Gateway endpoint URL for Prod environment for First Function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "First Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn diff --git a/go1.x/step-func/README.md b/go1.x/step-func/README.md deleted file mode 100644 index f55c6f885..000000000 --- a/go1.x/step-func/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Cookiecutter Go Step Functions Sample App (Stock Trader) for SAM based Serverless App - -A cookiecutter template to create a Go Step Functions Sample App (Stock Trader) boilerplate using [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). - -This application creates a stock trading workflow which runs on a pre-defined schedule. It demonstrates the power of Step Functions to orchestrate Lambda functions and other AWS resources to form complex and robust workflows, coupled with event-driven development using Amazon EventBridge. - -## Requirements - -* [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) - -## Usage - -Access this template by running `sam init` and choosing it from the list of available templates. - -# Credits - -* This project has been generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) \ No newline at end of file diff --git a/go1.x/step-func/__init__.py b/go1.x/step-func/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/step-func/cookiecutter.json b/go1.x/step-func/cookiecutter.json deleted file mode 100644 index 60a2a90c7..000000000 --- a/go1.x/step-func/cookiecutter.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "project_name": "Name of the project", - "runtime": "go1.x", - "architectures": { - "value": [ "x86_64" ] - }, - "_copy_without_render": [ - ".gitignore" - ] -} \ No newline at end of file diff --git a/go1.x/step-func/requirements-dev.txt b/go1.x/step-func/requirements-dev.txt deleted file mode 100644 index 151a0928c..000000000 --- a/go1.x/step-func/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -cookiecutter==2.3.0 -flake8==3.5.0 -pytest==3.3.2 -pytest-cookies==0.3.0 diff --git a/go1.x/step-func/tests/__init__.py b/go1.x/step-func/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/go1.x/step-func/tests/test_bake_project.py b/go1.x/step-func/tests/test_bake_project.py deleted file mode 100644 index 86f3db6fb..000000000 --- a/go1.x/step-func/tests/test_bake_project.py +++ /dev/null @@ -1,59 +0,0 @@ -from contextlib import contextmanager - -import os -import subprocess - - -@contextmanager -def inside_dir(dirpath): - """ - Execute code from inside the given directory - :param dirpath: String, path of the directory the command is being run. - """ - old_path = os.getcwd() - try: - os.chdir(dirpath) - yield - finally: - os.chdir(old_path) - - -def test_project_tree(cookies): - result = cookies.bake(extra_context={'project_name': 'test_project'}) - assert result.exit_code == 0 - assert result.exception is None - assert result.project.basename == 'test_project' - - assert result.project.isdir() - assert result.project.join('README.md').isfile() - assert result.project.join('template.yaml').isfile() - assert result.project.join('statemachines').isdir() - assert result.project.join('functions').isdir() - assert result.project.join('functions', 'stockBuyer').isdir() - assert result.project.join('functions', 'stockChecker').isdir() - assert result.project.join('functions', 'stockSeller').isdir() - - assert result.project.join('functions', 'stockBuyer').join('main.go').isfile() - assert result.project.join('functions', 'stockBuyer').join('main_test.go').isfile() - assert result.project.join('functions', 'stockChecker').join('main.go').isfile() - assert result.project.join('functions', 'stockChecker').join('main_test.go').isfile() - assert result.project.join('functions', 'stockSeller').join('main.go').isfile() - assert result.project.join('functions', 'stockSeller').join('main_test.go').isfile() - - -def test_app_template_content(cookies): - result = cookies.bake(extra_context={'project_name': 'test_project'}) - app_file = result.project.join('template.yaml') - app_content = app_file.readlines() - app_content = ''.join(app_content) - - contents = ( - "Runtime: go1.x", - "StockSellerFunction", - "StockBuyerFunction", - "StockCheckerFunction", - "StockTradingStateMachine" - ) - - for content in contents: - assert content in app_content diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/Makefile b/go1.x/step-func/{{cookiecutter.project_name}}/Makefile deleted file mode 100644 index a6699b6e8..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -.PHONY: build - -build: - sam build diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/README.md b/go1.x/step-func/{{cookiecutter.project_name}}/README.md deleted file mode 100644 index 57e4a88e3..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/README.md +++ /dev/null @@ -1,98 +0,0 @@ -# {{ cookiecutter.project_name }} - -This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders: - -- functions - Code for the application's Lambda functions to check the value of, buy, or sell shares of a stock. Also contains unit tests for the Lambda functions' application code. -- statemachines - Definition for the state machine that orchestrates the stock trading workflow. -- template.yaml - A template that defines the application's AWS resources. - -This application creates a stock trading workflow which runs on a pre-defined schedule (note that the schedule is disabled by default to avoid incurring charges). It demonstrates the power of Step Functions to orchestrate Lambda functions and other AWS resources to form complex and robust workflows, coupled with event-driven development using Amazon EventBridge. - -AWS Step Functions lets you coordinate multiple AWS services into serverless workflows so you can build and update apps quickly. Using Step Functions, you can design and run workflows that stitch together services, such as AWS Lambda, AWS Fargate, and Amazon SageMaker, into feature-rich applications. - -The application uses several AWS resources, including Step Functions state machines, Lambda functions and an EventBridge rule trigger. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code. - -If you prefer to use an integrated development environment (IDE) to build and test the Lambda functions within your application, you can use the AWS Toolkit. The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started: - -* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html) -* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html) -* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) - -The AWS Toolkit for VS Code includes full support for state machine visualization, enabling you to visualize your state machine in real time as you build. The AWS Toolkit for VS Code includes a language server for Amazon States Language, which lints your state machine definition to highlight common errors, provides auto-complete support, and code snippets for each state, enabling you to build state machines faster. - -## Deploy the sample application - -The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. - -To use the SAM CLI, you need the following tools: - -* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -* [Golang installed](https://golang.org) -* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) - -To build and deploy your application for the first time, run the following in your shell: - -```bash -sam build -sam deploy --guided -``` - -The first command will build the source of your application. The second command will package and deploy your application to AWS, with a series of prompts: - -* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. -* **AWS Region**: The AWS region you want to deploy your app to. -* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes. -* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. -* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application. - -## Use the SAM CLI to build locally -Build the Lambda functions in your application with the `sam build` command. -```bash -{{ cookiecutter.project_name }}$ sam build -``` -The SAM CLI installs dependencies defined in `functions//go.mod`, creates a deployment package, and saves it in the `.aws-sam/build` folder. - -## Add a resource to your application -The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in [the SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use standard [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html) resource types. - -## Fetch, tail, and filter Lambda function logs - -To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug. - -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. - -```bash -{{ cookiecutter.project_name }}$ sam logs -n StockCheckerFunction --stack-name {{ cookiecutter.project_name }} --tail -``` - -You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). - -## Unit tests - -Tests for the Lambda functions are defined in their respective `main_test.go` file. You can run all the tests by using the following command from your shell: - -```bash -{{ cookiecutter.project_name }}$ go test -v ./functions/... -``` - -## Cleanup - -To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following: - -```bash -sam delete --stack-name {{ cookiecutter.project_name }} -``` - -## Resources - -See the [AWS SAM developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) for an introduction to SAM specification, the SAM CLI, and serverless application concepts. - -Next, you can use AWS Serverless Application Repository to deploy ready to use Apps that go beyond hello world samples and learn how authors developed their applications: [AWS Serverless Application Repository main page](https://aws.amazon.com/serverless/serverlessrepo/) \ No newline at end of file diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/go.mod b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/go.mod deleted file mode 100644 index 9074ee9ad..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.8 - -module stockBuyer - -go 1.16 diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/go.sum b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/go.sum deleted file mode 100644 index d1ee29f48..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/go.sum +++ /dev/null @@ -1,13 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/main.go b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/main.go deleted file mode 100644 index 452cafe9c..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/main.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "context" - "github.com/aws/aws-lambda-go/lambda" - "math/rand" - "strconv" - "time" -) - -type StockEvent struct { - StockPrice int `json:"stockPrice"` -} - -type TransactionResult struct { - Id string `json:"id"` - Price string `json:"price"` - TransactionType string `json:"transactionType"` - Qty string `json:"qty"` - Timestamp string `json:"timestamp"` -} - -func handler(ctx context.Context, event StockEvent) (TransactionResult, error) { - // Sample Lambda function which mocks the operation of buying a random number - // of shares for a stock. - - // For demonstration purposes, this Lambda function does not actually perform any - // actual transactions. It simply returns a mocked result. - - // Parameters - // ---------- - // event: StockEvent, required - // Input event to the Lambda function - - // Returns - // ------ - // TransactionResult: Object containing details of the stock buying transaction - - // Get the price of the stock provided as input - stockPrice := event.StockPrice - - // Mocked result of a stock buying transaction - return TransactionResult{ - Id: strconv.FormatInt(rand.Int63n(1000), 10), // Unique ID for the transaction - Price: strconv.FormatInt(int64(stockPrice), 10), // Price of each share - TransactionType: "buy", // Type of transaction (buy/sell) - Qty: strconv.FormatInt((rand.Int63n(9) + 1), 10), // Number of shares bought/sold (We are mocking this as a random integer between 1 and 10) - Timestamp: time.Now().Format(time.RFC850), // Timestamp of the when the transaction was completed - }, nil -} - -func main() { - rand.Seed(11) - - lambda.Start(handler) -} diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/main_test.go b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/main_test.go deleted file mode 100644 index 0f6d92b40..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockBuyer/main_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "context" - "strconv" - "testing" -) - -func TestHandler(t *testing.T) { - t.Run("Check response properties", func(t *testing.T) { - event := StockEvent{StockPrice: 75} - context := context.Background() - response, _ := handler(context, event) - - _, idOk := interface{}(response.Id).(string) - price, priceOk := interface{}(response.Price).(string) - respType, typeOk := interface{}(response.TransactionType).(string) - _, qtyOk := interface{}(response.Qty).(string) - _, timestampOk := interface{}(response.Timestamp).(string) - - if !idOk || !priceOk || !typeOk || !qtyOk || !timestampOk { - t.Fatal("Response missing property") - } - - if respType != "buy" || price != strconv.FormatInt(int64(event.StockPrice), 10) { - t.Fatal("Response invalid property value") - } - }) -} diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/go.mod b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/go.mod deleted file mode 100644 index 4d542d733..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.8 - -module stockChecker - -go 1.16 diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/go.sum b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/go.sum deleted file mode 100644 index d1ee29f48..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/go.sum +++ /dev/null @@ -1,13 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/main.go b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/main.go deleted file mode 100644 index 36f8bc737..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "context" - "github.com/aws/aws-lambda-go/lambda" - "math/rand" -) - -type StockEvent struct { - StockPrice int `json:"stockPrice"` -} - -func handler(ctx context.Context) (StockEvent, error) { - // Sample Lambda function which mocks the operation of checking the current price - // of a stock. - - // For demonstration purposes this Lambda function simply returns - // a random integer between 0 and 100 as the stock price. - - // Parameters - // ---------- - // event: StockEvent, required - // Input event to the Lambda function - - // Returns - // ------ - // StockEvent: Object containing the current price of the stock - - // Check current price of the stock - return StockEvent{StockPrice: rand.Intn(100)}, nil // Current stock price is mocked as a random integer from 0 to 99 -} - -func main() { - rand.Seed(11) - - lambda.Start(handler) -} diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/main_test.go b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/main_test.go deleted file mode 100644 index e448c83a3..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockChecker/main_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "context" - "testing" -) - -func TestHandler(t *testing.T) { - t.Run("Check response properties", func(t *testing.T) { - context := context.Background() - response, _ := handler(context) - - if response.StockPrice < 0 || response.StockPrice > 99 { - t.Fatal("Response has invalid field value") - } - }) -} diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/go.mod b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/go.mod deleted file mode 100644 index 9e99a782b..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -require github.com/aws/aws-lambda-go v1.36.1 - -replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.8 - -module stockSeller - -go 1.16 diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/go.sum b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/go.sum deleted file mode 100644 index d1ee29f48..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/go.sum +++ /dev/null @@ -1,13 +0,0 @@ -github.com/aws/aws-lambda-go v1.36.1 h1:CJxGkL9uKszIASRDxzcOcLX6juzTLoTKtCIgUGcTjTU= -github.com/aws/aws-lambda-go v1.36.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/main.go b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/main.go deleted file mode 100644 index 56d063531..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/main.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "context" - "github.com/aws/aws-lambda-go/lambda" - "math/rand" - "strconv" - "time" -) - -type StockEvent struct { - StockPrice int `json:"stockPrice"` -} - -type TransactionResult struct { - Id string `json:"id"` - Price string `json:"price"` - TransactionType string `json:"transactionType"` - Qty string `json:"qty"` - Timestamp string `json:"timestamp"` -} - -func handler(ctx context.Context, event StockEvent) (TransactionResult, error) { - // Sample Lambda function which mocks the operation of selling a random number - // of shares for a stock. - - // For demonstration purposes, this Lambda function does not actually perform any - // actual transactions. It simply returns a mocked result. - - // Parameters - // ---------- - // event: StockEvent, required - // Input event to the Lambda function - - // Returns - // ------ - // TransactionResult: Object containing details of the stock selling transaction - - // Get the price of the stock provided as input - stockPrice := event.StockPrice - - // Mocked result of a stock selling transaction - return TransactionResult{ - Id: strconv.FormatInt(rand.Int63n(1000), 10), // Unique ID for the transaction - Price: strconv.FormatInt(int64(stockPrice), 10), // Price of each share - TransactionType: "sell", // Type of transaction (buy/sell) - Qty: strconv.FormatInt((rand.Int63n(9) + 1), 10), // Number of shares bought/sold (We are mocking this as a random integer between 1 and 10) - Timestamp: time.Now().Format(time.RFC850), // Timestamp of the when the transaction was completed - }, nil -} - -func main() { - rand.Seed(11) - - lambda.Start(handler) -} diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/main_test.go b/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/main_test.go deleted file mode 100644 index 1dc988d53..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/functions/stockSeller/main_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "context" - "strconv" - "testing" -) - -func TestHandler(t *testing.T) { - t.Run("Check response properties", func(t *testing.T) { - event := StockEvent{StockPrice: 75} - context := context.Background() - response, _ := handler(context, event) - - _, idOk := interface{}(response.Id).(string) - price, priceOk := interface{}(response.Price).(string) - respType, typeOk := interface{}(response.TransactionType).(string) - _, qtyOk := interface{}(response.Qty).(string) - _, timestampOk := interface{}(response.Timestamp).(string) - - if !idOk || !priceOk || !typeOk || !qtyOk || !timestampOk { - t.Fatal("Response missing property") - } - - if respType != "sell" || price != strconv.FormatInt(int64(event.StockPrice), 10) { - t.Fatal("Response invalid property value") - } - }) -} diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/statemachine/stockTrader.asl.json b/go1.x/step-func/{{cookiecutter.project_name}}/statemachine/stockTrader.asl.json deleted file mode 100644 index b93b0a489..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/statemachine/stockTrader.asl.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "Comment": "A state machine that does mock stock trading.", - "StartAt": "Check Stock Value", - "States": { - "Check Stock Value": { - "Type": "Task", - "Resource": "${StockCheckerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 15, - "MaxAttempts": 5, - "BackoffRate": 1.5 - } - ], - "Next": "Buy or Sell?" - }, - "Buy or Sell?": { - "Type": "Choice", - "Choices": [ - { - "Variable": "$.stockPrice", - "NumericLessThanEquals": 50, - "Next": "Buy Stock" - } - ], - "Default": "Sell Stock" - }, - "Sell Stock": { - "Type": "Task", - "Resource": "${StockSellerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 2, - "MaxAttempts": 3, - "BackoffRate": 1 - } - ], - "Next": "Record Transaction" - }, - "Buy Stock": { - "Type": "Task", - "Resource": "${StockBuyerFunctionArn}", - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 2, - "MaxAttempts": 3, - "BackoffRate": 1 - } - ], - "Next": "Record Transaction" - }, - "Record Transaction": { - "Type": "Task", - "Resource": "${DDBPutItem}", - "Parameters": { - "TableName": "${DDBTable}", - "Item": { - "Id": { - "S.$": "$.id" - }, - "Type": { - "S.$": "$.transactionType" - }, - "Price": { - "N.$": "$.price" - }, - "Quantity": { - "N.$": "$.qty" - }, - "Timestamp": { - "S.$": "$.timestamp" - } - } - }, - "Retry": [ - { - "ErrorEquals": [ - "States.TaskFailed" - ], - "IntervalSeconds": 20, - "MaxAttempts": 5, - "BackoffRate": 10 - } - ], - "End": true - } - } -} \ No newline at end of file diff --git a/go1.x/step-func/{{cookiecutter.project_name}}/template.yaml b/go1.x/step-func/{{cookiecutter.project_name}}/template.yaml deleted file mode 100644 index 5b9a1cc60..000000000 --- a/go1.x/step-func/{{cookiecutter.project_name}}/template.yaml +++ /dev/null @@ -1,94 +0,0 @@ -AWSTemplateFormatVersion: "2010-09-09" -Transform: AWS::Serverless-2016-10-31 -Description: > - {{ cookiecutter.project_name }} - - Sample SAM Template for {{ cookiecutter.project_name }} - -Resources: - StockTradingStateMachine: - Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html - Properties: - DefinitionUri: statemachine/stockTrader.asl.json - DefinitionSubstitutions: - StockCheckerFunctionArn: !GetAtt StockCheckerFunction.Arn - StockSellerFunctionArn: !GetAtt StockSellerFunction.Arn - StockBuyerFunctionArn: !GetAtt StockBuyerFunction.Arn - DDBPutItem: !Sub arn:${AWS::Partition}:states:::dynamodb:putItem - DDBTable: !Ref TransactionTable - Events: - HourlyTradingSchedule: - Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-schedule.html - Properties: - Description: Schedule to run the stock trading state machine every hour - Enabled: False - Schedule: "rate(1 hour)" - Policies: # Find out more about SAM policy templates: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html - - LambdaInvokePolicy: - FunctionName: !Ref StockCheckerFunction - - LambdaInvokePolicy: - FunctionName: !Ref StockSellerFunction - - LambdaInvokePolicy: - FunctionName: !Ref StockBuyerFunction - - DynamoDBWritePolicy: - TableName: !Ref TransactionTable - - StockCheckerFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html - Properties: - CodeUri: functions/stockChecker/ - Handler: stockChecker - Runtime: go1.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - - StockSellerFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: functions/stockSeller/ - Handler: stockSeller - Runtime: go1.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - - StockBuyerFunction: - Type: AWS::Serverless::Function - Properties: - CodeUri: functions/stockBuyer/ - Handler: stockBuyer - Runtime: go1.x - {%- if cookiecutter.architectures.value != []%} - Architectures: - {%- for arch in cookiecutter.architectures.value %} - - {{arch}} - {%- endfor %} - {%- endif %} - - TransactionTable: - Type: AWS::Serverless::SimpleTable # More info about SimpleTable Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-simpletable.html - Properties: - PrimaryKey: - Name: Id - Type: String - ProvisionedThroughput: - ReadCapacityUnits: 1 - WriteCapacityUnits: 1 - -Outputs: - # StockTradingStateMachineHourlyTradingSchedule is an implicit Schedule event rule created out of Events key under Serverless::StateMachine - # Find out more about other implicit resources you can reference within SAM - # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html - StockTradingStateMachineArn: - Description: "Stock Trading State machine ARN" - Value: !Ref StockTradingStateMachine - StockTradingStateMachineRoleArn: - Description: "IAM Role created for Stock Trading State machine based on the specified SAM Policy Templates" - Value: !GetAtt StockTradingStateMachineRole.Arn \ No newline at end of file diff --git a/manifest-v2.json b/manifest-v2.json index 83672d268..0936421f9 100644 --- a/manifest-v2.json +++ b/manifest-v2.json @@ -201,41 +201,6 @@ "useCaseName": "Hello World Example" } ], - "go1.x": [ - { - "directory": "go1.x/hello", - "displayName": "Hello World Example", - "dependencyManager": "mod", - "appTemplate": "hello-world", - "packageType": "Zip", - "useCaseName": "Hello World Example" - }, - { - "directory": "go1.x/event-bridge", - "displayName": "EventBridge Hello World", - "dependencyManager": "mod", - "appTemplate": "eventBridge-hello-world", - "packageType": "Zip", - "useCaseName": "Infrastructure event management" - }, - { - "directory": "go1.x/event-bridge-schema", - "displayName": "EventBridge App from scratch (100+ Event Schemas)", - "dependencyManager": "mod", - "appTemplate": "eventBridge-schema-app", - "isDynamicTemplate": "True", - "packageType": "Zip", - "useCaseName": "Infrastructure event management" - }, - { - "directory": "go1.x/step-func", - "displayName": "Step Functions Sample App (Stock Trader)", - "dependencyManager": "mod", - "appTemplate": "step-functions-sample-app", - "packageType": "Zip", - "useCaseName": "Multi-step workflow" - } - ], "go (provided.al2)": [ { "directory": "al2/go/hello", @@ -1534,16 +1499,6 @@ "useCaseName": "Hello World Example" } ], - "amazon/go1.x-base": [ - { - "directory": "go1.x/hello-img", - "displayName": "Hello World Lambda Image Example", - "dependencyManager": "mod", - "appTemplate": "hello-world-lambda-image", - "packageType": "Image", - "useCaseName": "Hello World Example" - } - ], "amazon/go-provided.al2-base": [ { "directory": "al2/go/hello-img", diff --git a/tests/integration/build_invoke/test_build_invoke_go1_x.py b/tests/integration/build_invoke/test_build_invoke_go1_x.py index 58fd76c69..55a8bef2f 100644 --- a/tests/integration/build_invoke/test_build_invoke_go1_x.py +++ b/tests/integration/build_invoke/test_build_invoke_go1_x.py @@ -12,10 +12,6 @@ """ -class BuildInvoke_go1_x_cookiecutter_aws_sam_hello_golang(BuildInvokeBase.BuildInvokeBase): - use_container = False - directory = "go1.x/hello" - class BuildInvoke_provided_go_cookiecutter_aws_sam_hello_golang(BuildInvokeBase.BuildInvokeBase): use_container = False directory = "al2/go/hello" @@ -24,10 +20,6 @@ class BuildInvoke_providedal2023_go_cookiecutter_aws_sam_hello_golang(BuildInvok use_container = False directory = "al2023/go/hello" -class BuildInvoke_go1_x_cookiecutter_aws_sam_eventbridge_hello_golang(BuildInvokeBase.BuildInvokeBase): - use_container = False - directory = "go1.x/event-bridge" - class BuildInvoke_provided_go_cookiecutter_aws_sam_eventbridge_hello_golang(BuildInvokeBase.BuildInvokeBase): use_container = False directory = "al2/go/event-bridge" @@ -36,22 +28,12 @@ class BuildInvoke_provided_go_cookiecutter_aws_sam_response_streaming_golang(Bui use_container = False directory = "al2/go/response-streaming" -# todo: remove skip once tests are run in environment with AWS Credentials -@skip("eventbridge schema app requires credential to pull missing files, skip") -class BuildInvoke_go1_x_cookiecutter_aws_sam_eventbridge_schema_app_golang(BuildInvokeBase.BuildInvokeBase): - use_container = False - directory = "go1.x/event-bridge-schema" - # todo: remove skip once tests are run in environment with AWS Credentials @skip("eventbridge schema app requires credential to pull missing files, skip") class BuildInvoke_provided_go_cookiecutter_aws_sam_eventbridge_schema_app_golang(BuildInvokeBase.BuildInvokeBase): use_container = False directory = "al2/go/event-bridge-schema" -class BuildInvoke_go1_x_cookiecutter_aws_sam_hello_step_functions_sample_app(BuildInvokeBase.BuildInvokeBase): - use_container = False - directory = "go1.x/step-func" - class BuildInvoke_provided_go_cookiecutter_aws_sam_hello_step_functions_sample_app(BuildInvokeBase.BuildInvokeBase): use_container = False directory = "al2/go/step-func" @@ -60,10 +42,6 @@ class BuildInvoke_provided_go_cookiecutter_aws_sam_hello_step_functions_sample_a # Image templates # - -class BuildInvoke_image_go1_x_cookiecutter_aws_sam_hello_golang_lambda_image(BuildInvokeBase.BuildInvokeBase): - directory = "go1.x/hello-img" - class BuildInvoke_image_provided_go_cookiecutter_aws_sam_hello_golang_lambda_image(BuildInvokeBase.BuildInvokeBase): directory = "al2/go/hello-img" diff --git a/tests/integration/unit_test/test_unit_test_go1_x.py b/tests/integration/unit_test/test_unit_test_go1_x.py index b432490ed..2056b75fd 100644 --- a/tests/integration/unit_test/test_unit_test_go1_x.py +++ b/tests/integration/unit_test/test_unit_test_go1_x.py @@ -2,10 +2,6 @@ from tests.integration.unit_test.unit_test_base import UnitTestBase -class UnitTest_go1_x_cookiecutter_aws_sam_hello_golang(UnitTestBase.GoUnitTestBase): - directory = "go1.x/hello" - code_directories = ["hello-world"] - class UnitTest_provided_go_cookiecutter_aws_sam_hello_golang(UnitTestBase.GoUnitTestBase): directory = "al2/go/hello" code_directories = ["hello-world"] @@ -14,28 +10,15 @@ class UnitTest_providedal2023_go_cookiecutter_aws_sam_hello_golang(UnitTestBase. directory = "al2023/go/hello" code_directories = ["hello-world"] -class UnitTest_go1_x_cookiecutter_aws_sam_eventbridge_hello_golang(UnitTestBase.GoUnitTestBase): - directory = "go1.x/event-bridge" - code_directories = ["hello-world"] - class UnitTest_provided_go_cookiecutter_aws_sam_eventbridge_hello_golang(UnitTestBase.GoUnitTestBase): directory = "al2/go/event-bridge" code_directories = ["hello-world"] -@skip("eventbridge schema app requires credential to pull missing files, skip") -class UnitTest_go1_x_cookiecutter_aws_sam_eventbridge_schema_app_golang(UnitTestBase.GoUnitTestBase): - directory = "go1.x/event-bridge-schema" - code_directories = ["hello-world"] - @skip("eventbridge schema app requires credential to pull missing files, skip") class UnitTest_provided_go_cookiecutter_aws_sam_eventbridge_schema_app_golang(UnitTestBase.GoUnitTestBase): directory = "al2/go/event-bridge-schema" code_directories = ["hello-world"] -class UnitTest_go1_x_cookiecutter_aws_sam_hello_step_functions_sample_app(UnitTestBase.GoUnitTestBase): - directory = "go1.x/step-func" - code_directories = ["functions/stockBuyer", "functions/stockChecker", "functions/stockSeller"] - class UnitTest_provided_go_cookiecutter_aws_sam_hello_step_functions_sample_app(UnitTestBase.GoUnitTestBase): directory = "al2/go/step-func" code_directories = ["functions/stockBuyer", "functions/stockChecker", "functions/stockSeller"]