Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple backends & minor fixes #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

armenr
Copy link
Owner

@armenr armenr commented May 5, 2021

Related Issue

awslabs#249

Description of changes

  • Generate env-specific props.json as ${env}-props.json
  • Generate unique name for each public key (avoid name collision/resource already exists error)
  • Enable multi-env support --> Successfully check out of/create multiple backend envs, each with its own set of amplify-video resources.
  • Capitalize generated GraphQL Models (VodAsset, VideoObject)

Pending PR code that's in this branch

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Currently-tested environment:

Amplify version: 4.49.0
NodeJS version: v14.16.1

@armenr armenr changed the title Armenr/fix multi env Support multiple backends & minor fixes May 6, 2021
Copy link

@arturocanalda arturocanalda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When changing amplify environment (amplify env checkout stg) a new props file was created (stg-props.json), which is correct.

When pushing I had the following issues:

CREATE_FAILED               rCloudFrontPublicKeyvv37ttp5                                                            AWS::CloudFront::PublicKey Thu May 06 2021 13:09:34 GMT+0200 (Central European Summer Time) Resource handler returned message: "Invalid request provided: AWS::CloudFront::PublicKey" (RequestToken: b653986f-72c3-87ce-129b-c26b609761d0, HandlerErrorCode: InvalidRequest)

I solved it by using the same public key I had on dev (which worked fine for some reason)

  • Once the key was hardcoded I could actually push, but the Cloudfront Private Secret Key
    (secretPem) is not created in AWS Secrets Manager.

@@ -307,7 +307,7 @@ async function createCDN(context, props, options, aws, oldValues) {
const uuid = Math.random().toString(36).substring(2, 6)
+ Math.random().toString(36).substring(2, 6);
const secretName = `${props.shared.resourceName}-${projectDetails.localEnvInfo.envName}-pem-${uuid}`.slice(0, 63);
const rPublicName = `rCloudFrontPublicKey${uuid}`.slice(0, 63);
const rPublicName = `rCloudFrontPublicKey${projectDetails.localEnvInfo.envName}${uuid}`.slice(0, 63);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armenr

If I'm looking at the right output file (dev-props.json), projectDetails.localEnvInfo.envName seems to be empty.

"contentDeliveryNetwork": {
        "signedKey": true,
        "publicKey": "****",
        "rPublicName": "rCloudFrontPublicKeyvv37ttp5",
        "publicKeyName": "vod-dev-publickey-vv37ttp5",
        "secretPem": "vod-dev-pem-vv37ttp5",
        "secretPemArn": "***",
        "functionName": "vod-dev-tokenGen",
        "functionNameSchema": "vod-${env}-tokenGen",
        "enableDistribution": true
    },

(*) Notice rCloudFrontPublicKeyvv37ttp5 doesn't contain the environment name ("dev")

Copy link
Owner Author

@armenr armenr May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturocanalda - Interesting. I'm comparing my results to yours, and there is a difference here. I'm wondering - what version of the amplify libs are you using?

I have a backend called ingrid, that was "auto-created" when I pushed a new branch to my codebase, and it produces this ingrid-props.json:

    "contentDeliveryNetwork": {
        "signedKey": true,
        "publicKey": "-----BEGIN PUBLIC KEY-----\\nREDACTED_KEY_MATERIALS\\n-----END PUBLIC KEY-----\\n",
        "rPublicName": "rCloudFrontPublicKeyingrid6b2201ks",
        "publicKeyName": "komitasv1-ingrid-publickey-6b2201ks",
        "secretPem": "komitasv1-ingrid-pem-6b2201ks",
        "secretPemArn": "******---komitasv1-ingrid-pem-6b2201ks-LoZRxw",
        "functionName": "komitasv1-ingrid-tokenGen",
        "functionNameSchema": "komitasv1-${env}-tokenGen",
        "enableDistribution": true
    },

This was "inherited" or "generated" from a staging-props.json which the plugin correctly created, that has the following in it:

  "contentDeliveryNetwork": {
    "signedKey": true,
    "publicKey": "-----BEGIN PUBLIC KEY-----\\n REDACTED_KEY_MATERIAL\\n-----END PUBLIC KEY-----\\n",
    "rPublicName": "rCloudFrontPublicKeystaging6b2201ks",
    "publicKeyName": "komitasv1-staging-publickey-6b2201ks",
    "secretPem": "komitasv1-staging-pem-6b2201ks",
    "secretPemArn": "*********---- komitasv1-staging-pem-6b2201ks-LoZRxw",
    "functionName": "komitasv1-staging-tokenGen",
    "functionNameSchema": "komitasv1-${env}-tokenGen",
    "enableDistribution": true
  },

As you can see, it appears to be working for me. I am running the following in my environment:

╰─ node -v
v14.16.1

╰─ amplify -v
4.49.0

Which version of node are you running, and which version of the amplify library?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armenr

Indeed, the versions we're using might be the reason why I'm experiencing this issue:

Node: 12.16.1  (maybe time for me to upgrade :)
Amplify: 4.50.2

I will upgrade nodeJS to 14.16.1 and test again later this afternoon. I'll keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants