Skip to main content

NPM version PyPI version .NET version Release

cdk-private-asset-bucket

A construct to create a private asset S3 bucket. Cognito will be used for token validation with Lambda@Edge.

Architecture

Diagram

Curious how I did the diagram? Have a look here https://martinmueller.dev/cdk-dia-eng .

Example

    import { PrivateAssetBucket } from 'cdk-private-assets-bucket';
    ...
    const userPool = new cognito.UserPool(stack, 'userPool', {
      removalPolicy: core.RemovalPolicy.DESTROY,
    });

    const userPoolWebClient = new cognito.UserPoolClient(stack, 'userPoolWebClient', {
      userPool: userPool,
      generateSecret: false,
      preventUserExistenceErrors: true,
      authFlows: {
        adminUserPassword: true,
        userPassword: true,
      },
      oAuth: {
        flows: {
          authorizationCodeGrant: false,
          implicitCodeGrant: true,
        },
      },
    });

    const privateAssetBucket = new PrivateAssetBucket(stack, 'privateAssetBucket', {
      userPoolId: userPool.userPoolId,
      userPoolClientId: userPoolWebClient.userPoolClientId,
      tokenUse: 'access',
    });

    new core.CfnOutput(stack, 'AssetBucketName', {
      value: privateAssetBucket.assetBucketName,
    });

    new core.CfnOutput(stack, 'AssetBucketCloudfrontUrl', {
      value: privateAssetBucket.assetBucketCloudfrontUrl,
    });

Properties

API.md

Test PrivateBucketAsset

If you forged / cloned that repo you can test directly from here. Don't forget to init with:

yarn install

Create a test cdk stack with one of the following:

yarn cdk deploy
yarn cdk deploy --watch
yarn cdk deploy --require-approval never
  • Upload a picture named like pic.png to the private asset bucket
  • Create a user pool user and get / save the token:
USER_POOL_ID=us-east-1_0Aw1oPvD6
CLIENT_ID=3eqcgvghjbv4d5rv32hopmadu8
USER_NAME=martindev
USER_PASSWORD=M@rtindev1
REGION=us-east-1
CFD=d1f2bfdek3mzi7.cloudfront.net

aws cognito-idp admin-create-user --user-pool-id $USER_POOL_ID --username $USER_NAME --region $REGION
aws cognito-idp admin-set-user-password --user-pool-id $USER_POOL_ID --username $USER_NAME --password $USER_PASSWORD  --permanent --region $REGION
ACCESS_TOKEN=$(aws cognito-idp initiate-auth --auth-flow USER_PASSWORD_AUTH --client-id $CLIENT_ID --auth-parameters USERNAME=$USER_NAME,PASSWORD=$USER_PASSWORD  --region $REGION | jq -r '.AuthenticationResult.AccessToken')

echo "curl --location --request GET "https://$CFD/pic.png" --cookie "Cookie: token=$ACCESS_TOKEN""
  • You can use the curl for importing in Postman. but it looks like Postman can't import the cookie. So you need to set the cookie manually in Postman!
  • In Postman you should see your picture :)
  • For Debugging the Lambda@Edge with Cloudwatch go to the AWS Console --> Cloudwatch --> Log groups --> switch to the region you are closest to --> figure out which log group is correct

Planned Features

  • Support custom authorizer
  • Leverage Cloudfront Function for cheaper costs

Misc

git tag -a v2.16.0 -m "prepare tag version" && git push --tags

Thanks To

I love to work on Content Management Open Source projects. A lot from my stuff you can already use on https://github.com/mmuller88. If you like my work there and my blog posts, please consider supporting me on Patreon:

Become a Patreon!

Buy Me a Coffee at ko-fi.com

Metadata

Release files for cdk-private-asset-bucket 2.25.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdk-private-asset-bucket 2.25.0
File Size Uploaded Provenance Actions
cdk-private-asset-bucket-2.25.0.tar.gz 10.0 MB Without provenance Details for cdk-private-asset-bucket-2.25.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cdk-private-asset-bucket 2.25.0
File Interpreter ABI Platform Actions
cdk_private_asset_bucket-2.25.0-py3-none-any.whl Python 3 none any Details for cdk_private_asset_bucket-2.25.0-py3-none-any.whl

Total release size: 20.0 MB

Release files / cdk-private-asset-bucket-2.25.0.tar.gz

Download URL cdk-private-asset-bucket-2.25.0.tar.gz
Size 10.0 MB
Tags Source
SHA-256 checksum
How to use checksums
92dd21ae08063e8f7a5c71c931da981102ea804e01d6358b3124e0975bd019a3
BLAKE2b-256 checksum
How to use checksums
9d184a7514e1212a21407781714877fcc1b86dc8447176f785144802988f8e67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / cdk_private_asset_bucket-2.25.0-py3-none-any.whl

Download URL cdk_private_asset_bucket-2.25.0-py3-none-any.whl
Size 10.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
3107f117d7651c6214ad277712b3468f727162ae3f38a11361f0051b11d526bb
BLAKE2b-256 checksum
How to use checksums
cf852fee6ff91911bfdfd9313b7463e6c0532419a1e8d56347db4b97557fef20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Security for cdk-private-asset-bucket 2.25.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page