Skip to content

Commit 654d06a

Browse files
committed
feat: updated readme for services to match workshop content.
1 parent ca02eea commit 654d06a

File tree

3 files changed

+48
-428
lines changed

3 files changed

+48
-428
lines changed

Unicorn.Contracts/README.md

Lines changed: 24 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,32 @@
1-
# ContractsService
1+
# Developing Unicorn Contracts
22

3-
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.
3+
![Contracts Service Architecture](https://static.us-east-1.prod.workshops.aws/public/fd291886-89c4-4336-b21b-5747484b495d/static/images/architecture-contracts.png)
44

5-
- src - Code for the application's Lambda function.
6-
- events - Invocation events that you can use to invoke the function.
7-
- test - Unit tests for the application code.
8-
- template.yaml - A template that defines the application's AWS resources.
5+
## Architecture overview
96

10-
The application uses several AWS resources, including Lambda functions and an API Gateway API. 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.
7+
Unicorn Contract manages the contractual relationship between the customers and the Unicorn Properties agency. It's primary function is to allow Unicorn Properties agents to create a new contract for a property listing, and to have the contract approved once it's ready.
118

12-
If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit.
13-
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.
9+
The architecture is fairly straight forward. An API exposes the create contract and update contract methods. This information is recorded in a Amazon DynamoDB table which will contain all latest information about the contract and it's status.
1410

15-
* [CLion](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
16-
* [GoLand](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
17-
* [IntelliJ](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
18-
* [WebStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
19-
* [Rider](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
20-
* [PhpStorm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
21-
* [PyCharm](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
22-
* [RubyMine](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
23-
* [DataGrip](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html)
24-
* [VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html)
25-
* [Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html)
11+
Each time a new contract is created or updated, Unicorn Contracts publishes a `ContractStatusChanged` event to Amazon EventBridge signalling changes to the contract status. These events are consumed by **Unicorn Properties**, so it can track changes to contracts, without needing to take a direct dependency on Unicorn Contracts and it's database.
2612

27-
## Deploy the sample application
13+
Here is an example of an event that is published to EventBridge:
2814

29-
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 and API.
30-
31-
To use the SAM CLI, you need the following tools.
32-
33-
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
34-
* .NET Core - [Install .NET Core](https://www.microsoft.com/net/download)
35-
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
36-
37-
To build and deploy your application for the first time, run the following in your shell:
38-
39-
```bash
40-
sam build
41-
sam deploy --guided
42-
```
43-
44-
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:
45-
46-
* **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.
47-
* **AWS Region**: The AWS region you want to deploy your app to.
48-
* **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.
49-
* **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.
50-
* **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.
51-
52-
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
53-
54-
## Use the SAM CLI to build and test locally
55-
56-
Build your application with the `sam build` command.
57-
58-
```bash
59-
ContractsService$ sam build
60-
```
61-
62-
The SAM CLI installs dependencies defined in `src/HelloWorld.csproj`, creates a deployment package, and saves it in the `.aws-sam/build` folder.
63-
64-
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.
65-
66-
Run functions locally and invoke them with the `sam local invoke` command.
67-
68-
```bash
69-
ContractsService$ sam local invoke HelloWorldFunction --event events/event.json
70-
```
71-
72-
The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000.
73-
74-
```bash
75-
ContractsService$ sam local start-api
76-
ContractsService$ curl http://localhost:3000/
77-
```
78-
79-
The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The `Events` property on each function's definition includes the route and method for each path.
80-
81-
```yaml
82-
Events:
83-
HelloWorld:
84-
Type: Api
85-
Properties:
86-
Path: /hello
87-
Method: get
88-
```
89-
90-
## Add a resource to your application
91-
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.
92-
93-
## Fetch, tail, and filter Lambda function logs
94-
95-
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.
96-
97-
`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
98-
99-
```bash
100-
ContractsService$ sam logs -n HelloWorldFunction --stack-name ContractsService --tail
101-
```
102-
103-
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).
104-
105-
## Unit tests
106-
107-
Tests are defined in the `test` folder in this project.
108-
109-
```bash
110-
ContractsService$ dotnet test test/HelloWorld.Test
111-
```
112-
113-
## Cleanup
114-
115-
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:
116-
117-
```bash
118-
sam delete --stack-name ContractsService
15+
```json
16+
{
17+
"version": "0",
18+
"account": "123456789012",
19+
"region": "us-east-1",
20+
"detail-type": "ContractStatusChanged",
21+
"source": "unicorn.contracts",
22+
"time": "2022-08-14T22:06:31Z",
23+
"id": "c071bfbf-83c4-49ca-a6ff-3df053957145",
24+
"resources": [],
25+
"detail": {
26+
"contract_updated_on": "10/08/2022 19:56:30",
27+
"ContractId": "617dda8c-e79b-406a-bc5b-3a4712f5e4d7",
28+
"PropertyId": "usa/anytown/main-street/111",
29+
"ContractStatus": "DRAFT"
30+
}
31+
}
11932
```
120-
121-
## Resources
122-
123-
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.
124-
125-
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/)

0 commit comments

Comments
 (0)