updating notes
This commit is contained in:
113
runningnotes.md
113
runningnotes.md
@@ -183,6 +183,8 @@ You can then run Strapi with `npm run develop` or `NODE_ENV=production npm run s
|
||||
|
||||
<https://adamtheautomator.com/aws-cli-cloudformation/> (example of deploying an S3 bucket with static site `index.html`.)
|
||||
|
||||
### Creating templates
|
||||
|
||||
To create a cloudformation template you should create a `template.yaml`. This yaml file should have at the top:
|
||||
|
||||
```yaml
|
||||
@@ -192,16 +194,125 @@ Description: A simple CloudFormation template
|
||||
|
||||
Then you should add a `Resources` key and populate this with all the infrastructure you need to provision.
|
||||
|
||||
### Creating templates
|
||||
### Adding resources
|
||||
|
||||
Documentation for all AWS resources is: <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html>.
|
||||
|
||||
A good approach is to use the GUI to create an object, and then lookup the cloudformation template as you go along.
|
||||
|
||||
### Using parameters
|
||||
|
||||
<https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html>
|
||||
|
||||
You can use parameters in your templates. This allows you to use names/resources from other templates, or specify them at creation on the CLI.
|
||||
|
||||
To use a parameter you should create a `Parameters` section in the yaml on the same level as a `Resources`.
|
||||
|
||||
```yaml
|
||||
Parameters:
|
||||
InstanceTypeParameter:
|
||||
Type: String
|
||||
Default: t2.micro
|
||||
AllowedValues:
|
||||
- t2.micro
|
||||
- m1.small
|
||||
- m1.large
|
||||
Description: Enter t2.micro, m1.small, or m1.large. Default is t2.micro.
|
||||
```
|
||||
|
||||
### Using outputs
|
||||
|
||||
<https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html>
|
||||
|
||||
### Using functions
|
||||
|
||||
A list of all Cloudformation functions is: <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html>.
|
||||
|
||||
`Fn::Select` will select a single object from a list of objects by index.
|
||||
|
||||
`Fn::GetAZs` returns an array that lists all availability zones for a specified region.
|
||||
|
||||
`!Ref` returns the value of the specified parameter or resource.
|
||||
|
||||
Example of these:
|
||||
|
||||
```yaml
|
||||
PublicSubnet1:
|
||||
Type: AWS::EC2::Subnet
|
||||
Properties:
|
||||
AvailabilityZone:
|
||||
Fn::Select:
|
||||
- 0
|
||||
- Fn::GetAZs: !Ref "AWS::Region"
|
||||
```
|
||||
|
||||
### Outputs
|
||||
|
||||
You can use the `Outputs:` header in your Cloudformation templates to specify outputs to be used in other Cloudformation templates.
|
||||
|
||||
<https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html>
|
||||
|
||||
```yaml
|
||||
Outputs:
|
||||
PublicVPCID:
|
||||
Description: The VPC ID.
|
||||
Value: !Ref PublicVPC
|
||||
Export:
|
||||
Name: ELBStrapiPublicVPC
|
||||
```
|
||||
|
||||
`Value` returns the value of the property by an `aws cloudformation describe-stacks` command. The value can contain literals, parameter references, pseudo-parameters, mapping values or functions.
|
||||
|
||||
`Name` goes under `Export:` and is used for cross-stack reference. This name should be unique within a region. You can use this name in other Cloudformation templates to reference the `Value` you have specified above. You can set content in other cloudformation templates this way.
|
||||
|
||||
You can refer to these in ELB `./config` files for example - allowing you to dynamically link to other AWS resources in your ELB environment.
|
||||
|
||||
### Referencing other resources
|
||||
|
||||
You can reference other resources in the template. This is useful say if you want to define a VPC and a subnet and reference the VPC from the subnet.
|
||||
|
||||
To do this you should use the `!Ref` function:
|
||||
|
||||
```yaml
|
||||
VpcId: !Ref PublicVPC
|
||||
```
|
||||
|
||||
#### Pesudeo references
|
||||
|
||||
You can also reference certain AWS references: <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html>.
|
||||
|
||||
Examples include `AWS::AccountId` and `AWS::StackName` among others.
|
||||
|
||||
### Deploy a stack/template
|
||||
|
||||
To deploy, you should run the command: `aws cloudformation deploy --template-file template.yaml --stack-name static-website`
|
||||
|
||||
### Tags
|
||||
|
||||
When setting tags you can set them on individual resources in the Cloudformation template:
|
||||
|
||||
```yaml
|
||||
Tags:
|
||||
- Key: git
|
||||
Value: web-dev
|
||||
- Key: owner
|
||||
Value: home
|
||||
- Key: project
|
||||
Value: strapi-elb
|
||||
- Key: test
|
||||
Value: true
|
||||
- Key: deployment
|
||||
Value: cloudformation
|
||||
```
|
||||
|
||||
Alternatively if you have many tags to be shared across all resources you can set them when you use the CLI to deploy: `--tags git=web-dev owner=home project=strapi-elb test=true deployment=cloudformation`
|
||||
|
||||
### Updating stack
|
||||
|
||||
To update a stack you can use `deploy`. Note that the default behaviour is to create the new resources side by side, then once successful remove the old ones. You may run into errors when updating certain resources (updating a VPC subnet will fail as it has to create the new subnet alongside the existing one). You should remove the old stack by doing `delete-stack` first.
|
||||
|
||||
`aws cloudformation delete-stack --stack-name temp-vpc --profile admin`
|
||||
|
||||
### Failure
|
||||
|
||||
If something goes wrong, you can use `describe-stack-events` and pass the `stack-name` to find the events leading up to the failure: `aws cloudformation describe-stack-events --stack-name strapi-s3`.
|
||||
|
||||
Reference in New Issue
Block a user