stackql-provider-awscc
Convert AWS CloudFormation Resource Specification to OpenAPI 3.0.0
Generating OpenAPI3 Specs and StackQL Provider
Follow the steps below to generate OpenAPI specs and a StackQL provider for AWS Cloud Control using CloudFormation schemas.
sh provider-dev/scripts/download-and-preprocess-defs.sh
2. Generate list of supported Cloud Control resources:
sh provider-dev/scripts/get_cc_supported_resources.sh
(requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars to be set)
3. run npm install
4. Generate OpenAPI specs and StackQL provider:
npm run generate-provider
output openapi3 specs (components/schemas) are written to opneapi/src/aws/v00.00.00000/services
5. Test resource coverage in the provider:
Verifies that every supported resource type in provider-dev/config/cc_supported_resources.js is accounted for in the generated provider:
npm run test-resource-coverage
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/openapi"
npm run start-server -- --provider awscc --registry $PROVIDER_REGISTRY_ROOT_DIR
npm run test-meta-routes -- awscc --ignore-no-methods --skip-resources awscc.tagging.tagged_resources
npm run stop-server
(awscc.tagging.tagged_resources is a native resource in a statically defined service; DESCRIBE does not return columns for it so it is excluded from the metadata route tests)
7. Testing locally with stackql
- ensure the
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are set
- download the latest
stackql binary, for example curl -L https://bit.ly/stackql-zip -O && unzip stackql-zip for Linux systems
- run the following:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)"
REG_STR='{"url": "file://'${PROVIDER_REGISTRY_ROOT_DIR}/openapi'", "localDocRoot": "'${PROVIDER_REGISTRY_ROOT_DIR}/openapi'", "verifyConfig": {"nopVerify": true}}'
./stackql shell --registry="${REG_STR}"
- run
stackql commands, for example
select * from awscc.s3.buckets_list_only WHERE region = 'us-east-1';
select bucket_name, region, bucket_encryption from awscc.s3.buckets WHERE region = 'us-east-1' and Identifier = 'stackql-trial-bucket-01';
select
ResourceARN as resource_arn,
json_extract(json_each.value, '$.Key') as key,
json_extract(json_each.value, '$.Value') as value
from awscc.tagging.tagged_resources, json_each(tags)
where region = 'us-east-1'
and ResourceTypeFilters = '["s3:bucket"]';
select resource_arn, key, value from
(
select
ResourceARN as resource_arn,
json_extract(json_each.value, '$.Key') as key,
json_extract(json_each.value, '$.Value') as value
from awscc.tagging.tagged_resources, json_each(tags)
where region = 'us-east-1'
and ResourceTypeFilters = '["s3:bucket"]'
and TagFilters = '[{"Key": "StackName", "Values": ["stackql-serverless"]}]'
) t
where key = 'StackName' and value = 'stackql-serverless';
8. Generate web docs:
npm run generate-docs
output markdown docs are written to website/docs
9. Test web docs locally
cd website
# test build
yarn build
# run local dev server
yarn start
10. Publish web docs to GitHub Pages
Under Pages in the repository, in the Build and deployment section select GitHub Actions as the Source. In Netlify DNS create the following records:
Troubleshooting AWS Cloud Control
To troubleshoot AWS Cloud Control API requests (mutation requests), use the following queries:
select * from awscc.cloud_control.resource_requests
where ResourceRequestStatusFilter = '{"OperationStatuses": ["FAILED"], "Operations": ["CREATE"]}'
and region = 'ap-southeast-2';
--or
select * from awscc.cloud_control.resource_requests
where ResourceRequestStatusFilter = '{"OperationStatuses": ["FAILED"], "Operations": ["DELETE"]}'
and region = 'us-east-1';
--or
select * from awscc.cloud_control.resource_requests
where ResourceRequestStatusFilter = '{"OperationStatuses": ["SUCCESS"], "Operations": ["UPDATE"]}'
and region = 'ap-southeast-2';
(replace region accordingly)
select * from awscc.cloud_control.resource_request
where RequestToken = '54061545-e0a0-4ef0-b213-41fda81d8c24'
and region = 'ap-southeast-2';
(replace region and RequestToken accordingly)
Resolving Identifiers
To resolve resource identifiers you can use tags, such as:
SELECT
json_extract(value, '$.ResourceARN') as arn
FROM awscc.tagging.tagged_resources, json_each(ResourceTagMappingList)
WHERE
region = 'us-east-1'
AND TagFilters = '[
{"Key": "StackName","Values": ["stackql-serverless"]},
{"Key": "StackEnv","Values": ["prd"]}
]'
AND TagsPerPage = 100;
Checking for AWS CC updates
See here for newly added or updated Cloud Control resources.
License
MIT
评论