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

Failed to sync output fields after first deploy #118

Closed
titanjer opened this issue Nov 16, 2020 · 0 comments · Fixed by #120
Closed

Failed to sync output fields after first deploy #118

titanjer opened this issue Nov 16, 2020 · 0 comments · Fixed by #120

Comments

@titanjer
Copy link

titanjer commented Nov 16, 2020

I use this package for lambda@edge scenario. However, I get wrong CFN output fields (ap-northeast-1) after deployments for changed lambda code (us-east-1). Every time I modified lambda code in us-east-1 stack, the stack in ap-northeast-1 can not aware the changed.

You can see the two stack outputs below. NumLambdaEdgeStack.LambdaFuncArn (v4) and NumCloudfrontStack.OutputLambdaFuncArn (v2) should be the same.

Screen Shot 2020-11-11 at 11 29 03 PM

Below is my code.

// lambda in us-east-1
export class NumLambdaEdgeStack extends Stack {

  constructor(scope: Construct, id: string, props: StackProps = {}) {
    super(scope, id, props);

    const managedPolicyArn = iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole');

    const func = new PythonFunction(this, 'LambdaEdgeFunction', {
      entry: path.join(__dirname, './lambda/lambda-edge'),
      handler: 'handler',
      runtime: lambda.Runtime.PYTHON_3_8,
      role: new iam.Role(this, 'EdgeLambdaServiceRole', {
        assumedBy: new iam.CompositePrincipal(
          new iam.ServicePrincipal('lambda.amazonaws.com'),
          new iam.ServicePrincipal('edgelambda.amazonaws.com'),
        ),
        managedPolicies: [managedPolicyArn],
      }),
    });

    new CfnOutput(this, 'LambdaFuncArn', { value: func.currentVersion.functionArn });
  }
}
// cloudfront in ap-northeast-1
export interface NumCloudfrontStackProps extends StackProps {
  readonly lambdaStack: NumLambdaEdgeStack;
}

export class NumCloudfrontStack extends Stack {
  constructor(scope: Construct, id: string, props: NumCloudfrontStackProps) {
    super(scope, id, props);

    const outputs = new StackOutputs(this, 'LambdaFuncArn', {
      stack: props.lambdaStack,
    });
    const lambdaFuncArn = outputs.getAttString('LambdaFuncArn');

    origin = .....
    originRequestPolicy = .....

    const cf = new cloudfront.Distribution(this, 'Cloudfront', {
      defaultBehavior: {
        origin,
        originRequestPolicy,
        edgeLambdas: [
          {
            functionVersion: lambda.Version.fromVersionArn(this, 'EdgeLambdaFunctionArn', lambdaFuncArn),
            eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
          },
        ],
      },
      comment: 'num-cloudfront-test',
    });

    new CfnOutput(this, 'OutputLambdaFuncArn', { value: lambdaFuncArn });
  }
}
@mergify mergify bot closed this as completed in #120 Nov 16, 2020
mergify bot pushed a commit that referenced this issue Nov 16, 2020
- add `alwaysUpdate` property for `StackOutput` to force get the output from the source stack.

Fixes #118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant