Skip to content

Custom Resource GetAtt not working #561

@YamiDaisuke

Description

@YamiDaisuke

Guidance Question

Custom Resource GetAtt not working

The Question

Hi!, I'm trying to use a CustomResource to create a MediaTailor channel, so far the scripts go well and the channel gets created but I have two issues:

First problem:

From my lambda function I'm returning the following object:

{
    "Status": "SUCCESS",
    "PhysicalResourceId": "mediaTailorPlaybackConfigName",
    "StackId": "arn:aws:cloudformation:us-east-1:.....",
    "RequestId": "......",
    "LogicalResourceId": "mediaTailorresource7FE79038",
    "Data": {
        "Arn": "arn:aws:mediatailor:us-east-1:XXXXX:playbackConfiguration/mediaTailorPlaybackConfigName",
        "HLS": "https://xxxxxxxxxxxxxxxxxxx.mediatailor.us-east-1.amazonaws.com/v1/master/xxxxxxxxxxx",
        "DASH": "https://xxxxxxxxxxxxxxxxx.mediatailor.us-east-1.amazonaws.com/v1/dash/xxxxxxxxxxxxx"
    }
}

When I try to use resource.getAtt('HLS').toString() I get the following error:

CustomResource attribute error: Vendor response doesn't contain HLS key in object arn:aws:cloudformation:us-east-1:829011433133:stack/xxxxxxxx|mediaTailorResourcexxxxxxxxxxxxxxx in S3 bucket cloudformation-custom-resource-storage-useast1

The second case happens during rollback, even though I'm returning a "PhysicalResourceId" the "DELETE" action receives the same "RequestId" as "PhysicalResourceId" so I don't have a way to find the actual resource and delete it

CDK CLI Version

1.102.0

Example

// For Lambda handler I'm currently using this sample script: 
var response = require('cfn-response');
exports.handler = function (event, context) {
    console.log('REQUEST RECEIVED:\n' + JSON.stringify(event));

    if (event.RequestType === 'Create') {
        console.log('CREATE!');
        response.send(event, context, response.SUCCESS, { 'Message': 'Resource creation successful!', 'HLS': 'hellofromtheotherside.com' });
    } else if (event.RequestType === 'Update') {
        console.log('UDPATE!');
        response.send(event, context, response.SUCCESS, { 'Message': 'Resource update successful!', 'HLS': 'hellofromtheotherside.com' });
    } else if (event.RequestType === 'Delete') {
        console.log('DELETE!');
        response.send(event, context, response.SUCCESS, { 'Message': 'Resource deletion successful!', 'HLS': 'hellofromtheotherside.com' });
    } else {
        console.log('FAILED!');
        response.send(event, context, response.FAILED);
    }
};



// CDK Construct 
class MediaTailorConfig extends cdk.Construct {

    constructor(scope, id, props) {
        super(scope, id, props);

        const onEvent = new lambda.SingletonFunction(this, 'resource', {
            uuid: 'xxxxxxxxxxx',
            code: lambda.Code.fromAsset(path.join(__dirname, 'cfn-mediatailor/index.js.zip'), { encoding: 'utf-8' }),
            handler: 'index.handler',
            timeout: cdk.Duration.seconds(300),
            runtime: lambda.Runtime.NODEJS_14_X,
        });

        const myProvider = new cr.Provider(this, 'MediaTailorProvider', {
            onEventHandler: onEvent,
            logRetention: logs.RetentionDays.TWO_WEEKS, 
        });

        const resource = new cdk.CustomResource(this, 'resource', { serviceToken: myProvider.serviceToken, properties: props });

        this.hls = resource.getAtt('HLS').toString();
    }

}

Example Version

No response

OS

macOS

Language

Typescript

Other information

No response

Metadata

Metadata

Assignees

Labels

guidanceQuestion that needs advice or information.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions