AWS Certified Developer – Associate / Question #783 of 557

Question #783

Given the following AWS CloudFormation template:

yaml<br>Description: Create a new Amazon RDS database instance. Uses a DB instance identifier to avoid conflict.<br>Resources:<br> MyDBInstance:<br> Type: AWS::RDS::DBInstance<br> Properties:<br> AllocatedStorage: 20<br> DBInstanceClass: db.t3.micro<br> Engine: mysql<br> MasterUsername: admin<br> MasterUserPassword: !Ref DBMasterPassword<br>Outputs:<br> DBEndpoint:<br> Value: !GetAtt MyDBInstance.Endpoint.Address<br>

What is the MOST efficient way to reference the database endpoint from another AWS CloudFormation template?

A

Add an Export declaration to the Outputs section of the original template and use Fn::ImportValue in other templates.

B

Add Exported: true to the MyDBInstance resource in the original template and use ImportResource in other templates.

C

Create a custom AWS CloudFormation resource that retrieves the endpoint from the MyDBInstance resource of the first stack.

D

Use Fn::Merge to combine the existing template with other templates and reference the DBEndpoint output directly.

Explanation

Answer A is correct because AWS CloudFormation's Export declaration in the Outputs section allows resources from one stack to be securely referenced in another stack using Fn::ImportValue. This is the native, most efficient method for cross-stack resource sharing.

Why other options are incorrect:
- B: There is no Exported: true property for resources; exports are defined in Outputs.
- C: Custom resources add unnecessary complexity compared to built-in export/import functionality.
- D: Fn::Merge is not a valid CloudFormation function, and merging templates does not enable cross-stack references.

Key Points:
1. Use Export in Outputs to expose values across stacks.
2. Use Fn::ImportValue to import exported values in other templates.
3. Avoid custom solutions when native features suffice.

Answer

The correct answer is: A