0.0.77 • Published 4 months ago

@awsless/formation v0.0.77

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Infrastructure as code made fast & easy

The @awsless/formation package is a TypeScript API that provides an infrastructure as code solution for AWS.

The problem

The most used IaC solutions are slow & don't effectively leverage diffing to speed up their deployments.

Todo's

  • When a resource is being deleted inside a deployment we need to make sure that resources that depend on our deleted resource will be updated first.

Setup

Install with (NPM):

npm i @awsless/formation

Example

First, you need to create a workspace instance and pass in the cloud providers that you will use. We also need to give it a lock provider & state provider.

  • A cloud provider is used to create resources on a specific cloud provider. We have built-in cloud providers for AWS resources, but you could simply add your own as well.

  • The state provider is used for storing the latest deployment state.

  • The lock provider is used for acquiring a lock when you deploy your app. This will guarantee that multiple people can never deploy the same application at the same time.

In this example, we will use a local file lock & state provider.

import { minutes } from '@awsless/duration'
import { fromIni } from '@aws-sdk/credential-providers'
import { App, FileStateBackend, FileLockBackend, $, Terraform, Stack, WorkSpace } from '@awsless/formation'

const terraform = new Terraform({
	providerLocation: './providers'
})

const aws = await terraform.install('hashicorp', 'aws', '5.93.0')

const workspace = new WorkSpace({
	providers: [
		aws({
			profile: "PROFILE",
			region: "REGION"
		})
	],
	backend: {
		state: new FileStateBackend({ dir: './states' }),
		lock: new FileLockBackend({ dir: './locks' }),
	}
})

With your workspace configuration ready we can now move on to defining your infrastructure. This example illustrates how simple it is to define multi-stack resources without worrying about cross-stack references.

const app = new App('todo-app')
const storage = new Stack(app, 'storage')
const list = new $.aws.s3.Bucket(storage, 'list', {})

const items = new Stack(app, 'items')
const todo = new $.aws.s3.BucketObject(items, 'item', {
	bucket: list.bucket,
	key: 'item-1',
	content: JSON.stringify({
		title: 'Write docs...',
		done: true,
	}),
})

After defining your infrastructure, we can deploy our app.

await workspace.deploy(app)

Or destroy our app.

await workspace.delete(app)

Maybe you want to only deploy a subset of stacks.

await workspace.deploy(app, {
	filters: ["storage"]
})

Production

For production, we recommend you use a state & lock backend that stores your data in the cloud. An AWS DynamoDB table is perfect for storing locks. While AWS S3 is perfect for storing your state files.

const workspace = new WorkSpace({
	providers: [...],
	backend: {
		lock: new DynamoLockBackend({
  			region,
  			credentials,
  			tableName: 'awsless-locks',
  		}),
		state: new S3StateBackend({
			region,
			credentials,
			bucket: 'awsless-state-UNIQUE_ID',
		}),
	}
})
0.0.73

5 months ago

0.0.74

4 months ago

0.0.75

4 months ago

0.0.76

4 months ago

0.0.77

4 months ago

0.0.70

5 months ago

0.0.71

5 months ago

0.0.72

5 months ago

0.0.62

7 months ago

0.0.63

6 months ago

0.0.64

6 months ago

0.0.65

6 months ago

0.0.66

6 months ago

0.0.68

6 months ago

0.0.69

5 months ago

0.0.60

7 months ago

0.0.61

7 months ago

0.0.59

8 months ago

0.0.57

11 months ago

0.0.58

8 months ago

0.0.54

1 year ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

2 years ago